001: /*
002: * JSCommentOptionPane.java - JavaStyle options panel for C-style comments
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.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 16 July 2003
035: *@version $Version: $
036: *@since 1.0
037: */
038: public class JSCommentOptionPane extends JSHelpOptionPane {
039:
040: private JCheckBox formatCStyle;
041: private JCheckBox fillCStyleWithStars;
042: private JCheckBox alignCStyle;
043: private JCheckBox ownLine;
044: private JCheckBox csOwnLine;
045: private JCheckBox ownLineIndent;
046: private JCheckBox appendedIndent;
047: private JTextField absoluteIndent;
048: private JTextField incrementalIndent;
049: private JTextField cStyleIndent;
050:
051: private SelectedPanel formatCStyle_sp;
052: private SelectedPanel fillCStyleWithStars_sp;
053: private SelectedPanel alignCStyle_sp;
054: private SelectedPanel cStyleIndent_sp;
055: private SelectedPanel ownLine_sp;
056: private SelectedPanel csOwnLine_sp;
057: private SelectedPanel appendedIndent_sp;
058: private SelectedPanel ownLineIndent_sp;
059: private SelectedPanel absoluteIndent_sp;
060: private SelectedPanel incrementalIndent_sp;
061:
062: /**
063: * Constructor for the JSCommentOptionPane object
064: *
065: *@param project Description of the Parameter
066: */
067: public JSCommentOptionPane(String project) {
068: super ("javastyle.comments", "pretty", project);
069: }
070:
071: /**
072: * Description of the Method
073: */
074: public void _init() {
075: ActionHandler ah = new ActionHandler();
076:
077: String cStyleFormat = props.getString("c.style.format");
078:
079: // "Format C-style comments"
080: formatCStyle = new JCheckBox();
081: formatCStyle_sp = addComponent("c.style.format", "csFormat",
082: formatCStyle);
083: formatCStyle.setSelected(!cStyleFormat.equals("leave"));
084: formatCStyle.addActionListener(ah);
085:
086: // "Fill C-style comments with stars on the left"
087: fillCStyleWithStars = new JCheckBox();
088: fillCStyleWithStars_sp = addComponent(null, "csFillWithStars",
089: fillCStyleWithStars);
090: fillCStyleWithStars.setSelected(cStyleFormat
091: .equals("maintain.space.star")
092: || cStyleFormat.equals("align.star"));
093: fillCStyleWithStars.addActionListener(ah);
094:
095: // "Align text to the left in C-style comments"
096: alignCStyle = new JCheckBox();
097: alignCStyle_sp = addComponent(null, "csAlign", alignCStyle);
098: alignCStyle.setSelected(cStyleFormat.equals("align.blank")
099: || cStyleFormat.equals("align.star"));
100: alignCStyle.addActionListener(ah);
101:
102: // "Number of spaces to indent: xxx"
103: cStyleIndent = new JTextField();
104: cStyleIndent_sp = addComponent("c.style.indent",
105: "csIndentAmount", cStyleIndent);
106:
107: // "Put end-line comments on an own line"
108: ownLine = new JCheckBox();
109: ownLine.addActionListener(ah);
110: ownLine_sp = addComponent("singleline.comment.ownline",
111: "slOwnLine", ownLine);
112:
113: csOwnLine = new JCheckBox();
114: csOwnLine.addActionListener(ah);
115: csOwnLine_sp = addComponent("cstyle.comment.ownline",
116: "treatSLasCS", csOwnLine);
117:
118: // "Indent end-line comments to a certain column"
119: appendedIndent = new JCheckBox();
120: String indentstyle_shared = props
121: .getString("singleline.comment.indentstyle.shared");
122: //System.out.println("indentstyle_shared="+indentstyle_shared);
123: appendedIndent_sp = addComponent(
124: "singleline.comment.indentstyle.shared",
125: "slAppendedIndent", appendedIndent);
126: //boolean flag = indentstyle_shared.toUpperCase().startsWith("A");
127: appendedIndent.setSelected(indentstyle_shared.toUpperCase()
128: .startsWith("A"));
129: //System.out.println("indentstyle_shared flag="+flag);
130: appendedIndent.addActionListener(ah);
131:
132: // "Indent single line comments to a certain column"
133: ownLineIndent = new JCheckBox();
134: ownLineIndent_sp = addComponent(
135: "singleline.comment.indentstyle.ownline",
136: "slOwnLineIndent", ownLineIndent);
137: String indentstyle_ownline = props
138: .getString("singleline.comment.indentstyle.ownline");
139: //System.out.println("indentstyle_ownline="+indentstyle_ownline);
140: //boolean flag2 = indentstyle_ownline.toUpperCase().startsWith("A");
141: ownLineIndent.setSelected(indentstyle_ownline.toUpperCase()
142: .startsWith("A"));
143: //System.out.println("indentstyle_ownline flag="+flag2);
144: ownLineIndent.addActionListener(ah);
145:
146: // "Indent to column: xxx"
147: absoluteIndent = new JTextField();
148: absoluteIndent_sp = addComponent(
149: "singleline.comment.absoluteindent",
150: "slAbsoluteIndent", absoluteIndent);
151:
152: // "Space between code and comment: xxx"
153: incrementalIndent = new JTextField();
154: incrementalIndent_sp = addComponent(
155: "singleline.comment.incrementalindent",
156: "slIncrementalIndent", incrementalIndent);
157:
158: addHelpArea();
159: ah.update();
160: }
161:
162: /**
163: * Called when the options dialog's `OK' button is pressed. This should
164: * save any properties saved in this option pane.
165: */
166: public void _save() {
167: String cStyleFormat = "leave";
168: if (formatCStyle.isSelected()) {
169: if (fillCStyleWithStars.isSelected()) {
170: if (alignCStyle.isSelected()) {
171: cStyleFormat = "align.star";
172: } else {
173: cStyleFormat = "maintain.space.star";
174: }
175: } else {
176: cStyleFormat = "align.blank";
177: }
178: }
179:
180: formatCStyle_sp.save(cStyleFormat);
181: cStyleIndent_sp.saveInt(0, 0);
182: ownLine_sp.save();
183: csOwnLine_sp.save();
184: //appendedIndent_sp.save();
185: if (appendedIndent.isSelected()) {
186: System.out
187: .println("JSCommentOptionPane:appendedIndent.isSelected()=true");
188: appendedIndent_sp.save("absolute");
189: } else {
190: appendedIndent_sp.save("incremental");
191: }
192: if (ownLineIndent.isSelected()) {
193: ownLineIndent_sp.save("absolute");
194: } else {
195: ownLineIndent_sp.save("code");
196: }
197: absoluteIndent_sp.saveInt(0, 0);
198: incrementalIndent_sp.saveInt(0, 0);
199: }
200:
201: /**
202: * Description of the Class
203: *
204: *@author Mike
205: *@created 16 July 2003
206: */
207: private class ActionHandler implements ActionListener {
208:
209: /**
210: * Description of the Method
211: *
212: *@param evt Description of the Parameter
213: */
214: public void actionPerformed(ActionEvent evt) {
215: update();
216:
217: if (evt.getSource() == fillCStyleWithStars) {
218: if (!fillCStyleWithStars.isSelected()
219: && !alignCStyle.isSelected()) {
220: alignCStyle.setSelected(true);
221: }
222: } else if (evt.getSource() == alignCStyle) {
223: if (!fillCStyleWithStars.isSelected()
224: && !alignCStyle.isSelected()) {
225: fillCStyleWithStars.setSelected(true);
226: }
227: }
228:
229: cStyleIndent.setEnabled(formatCStyle.isSelected()
230: && alignCStyle.isSelected());
231: }
232:
233: /**
234: * Description of the Method
235: */
236: public void update() {
237: fillCStyleWithStars.setEnabled(formatCStyle.isSelected());
238: alignCStyle.setEnabled(formatCStyle.isSelected());
239: cStyleIndent.setEnabled(formatCStyle.isSelected()
240: && alignCStyle.isSelected());
241:
242: appendedIndent.setEnabled(!ownLine.isSelected());
243: absoluteIndent.setEnabled(ownLineIndent.isSelected()
244: || appendedIndent.isSelected());
245: incrementalIndent.setEnabled(!ownLine.isSelected()
246: && !appendedIndent.isSelected());
247: }
248:
249: }
250: }
|