2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.tasklist.todo.settings;
44
import java.beans.PropertyChangeListener;
45
import java.beans.PropertyChangeSupport;
46
import java.util.ArrayList;
47
import java.util.Collection;
48
import java.util.Collections;
49
import java.util.HashMap;
51
import java.util.StringTokenizer;
52
import java.util.prefs.Preferences;
53
import org.openide.util.NbPreferences;
59
final public class Settings {
61
public static final String PROP_PATTERN_LIST = "patternList"; //NOI18N
62
public static final String PROP_SCAN_COMMENTS_ONLY = "scanCommentsOnly"; //NOI18N
64
private static Settings theInstance;
65
private static final String PATTERN_DELIMITER = "|"; //NOI18N
67
private ArrayList<String> patterns = new ArrayList<String>( 10 );
68
private Map<String, CommentTags> ext2comments = new HashMap<String, CommentTags>( 10 );
69
private Map<String, CommentTags> mime2comments = new HashMap<String, CommentTags>( 10 );
70
private boolean scanCommentsOnly = true;
72
private PropertyChangeSupport propertySupport;
74
/** Creates a new instance of Settings */
76
patterns.addAll( decodePatterns( getPreferences().get( "patterns", //NOI18N
77
"@todo|TODO|FIXME|XXX|PENDING|<<<<<<<" )) ); //NOI18N
79
scanCommentsOnly = getPreferences().getBoolean( "scanCommentsOnly", true ); //NOI18N
81
ext2comments.put( "JAVA", new CommentTags( "//", "/*", "*/") ); //NOI18N //NOI18N //NOI18N //NOI18N
82
ext2comments.put( "C", new CommentTags( "//", "/*", "*/") ); //NOI18N //NOI18N //NOI18N //NOI18N
83
ext2comments.put( "CPP", new CommentTags( "//", "/*", "*/") ); //NOI18N //NOI18N //NOI18N //NOI18N
84
ext2comments.put( "CXX", new CommentTags( "//", "/*", "*/") ); //NOI18N //NOI18N //NOI18N //NOI18N
85
ext2comments.put( "HTML", new CommentTags( "<!--", "-->") ); //NOI18N //NOI18N //NOI18N
86
ext2comments.put( "HTM", new CommentTags( "<!--", "-->") ); //NOI18N //NOI18N //NOI18N
87
ext2comments.put( "XML", new CommentTags( "<!--", "-->") ); //NOI18N //NOI18N //NOI18N
88
ext2comments.put( "JSP", new CommentTags( "<%--", "--%>") ); //NOI18N //NOI18N //NOI18N
89
ext2comments.put( "PROPERTIES", new CommentTags("#") ); //NOI18N //NOI18N
90
ext2comments.put( "SH", new CommentTags("#") ); //NOI18N //NOI18N
91
ext2comments.put( "RB", new CommentTags("#") ); //NOI18N //NOI18N
93
mime2comments.put( "text/x-java", new CommentTags( "//", "/*", "*/") ); //NOI18N //NOI18N //NOI18N //NOI18N
94
mime2comments.put( "text/html", new CommentTags( "<!--", "-->") ); //NOI18N //NOI18N //NOI18N
95
mime2comments.put( "application/x-httpd-eruby", new CommentTags( "<!--", "-->") ); //NOI18N //NOI18N //NOI18N
96
mime2comments.put( "text/x-ruby", new CommentTags("#") ); //NOI18N //NOI18N
99
public static final Settings getDefault() {
100
if( null == theInstance )
101
theInstance = new Settings();
105
public Collection<String> getPatterns() {
106
return Collections.unmodifiableCollection( patterns );
109
public void setPatterns( Collection<String> newPatterns ) {
111
patterns.addAll( newPatterns );
112
getPreferences().put( "patterns", encodePatterns(newPatterns) ); //NOI18N
113
if( null == propertySupport )
114
propertySupport = new PropertyChangeSupport( this );
115
propertySupport.firePropertyChange( PROP_PATTERN_LIST, null, getPatterns() );
118
public boolean isExtensionSupported( String fileExtension ) {
119
return null != ext2comments.get( fileExtension.toUpperCase() );
122
public boolean isMimeTypeSupported( String mimeType ) {
123
return null != mime2comments.get( mimeType );
126
public String getLineComment( String fileExtension, String mime ) {
127
CommentTags ct = ext2comments.get( fileExtension.toUpperCase() );
129
ct = mime2comments.get( mime );
130
return null == ct ? null : ct.lineComment;
133
public String getBlockCommentStart( String fileExtension, String mime ) {
134
CommentTags ct = ext2comments.get( fileExtension.toUpperCase() );
136
ct = mime2comments.get( mime );
137
return null == ct ? null : ct.blockCommentStart;
140
public String getBlockCommentEnd( String fileExtension, String mime ) {
141
CommentTags ct = ext2comments.get( fileExtension.toUpperCase() );
143
ct = mime2comments.get( mime );
144
return null == ct ? null : ct.blockCommentEnd;
147
public boolean isScanCommentsOnly() {
148
return scanCommentsOnly;
151
public void setScanCommentsOnly( boolean val ) {
152
boolean oldVal = scanCommentsOnly;
153
this.scanCommentsOnly = val;
154
getPreferences().putBoolean( "scanCommentsOnly", val ); //NOI18N
155
if( null == propertySupport )
156
propertySupport = new PropertyChangeSupport( this );
157
propertySupport.firePropertyChange( PROP_SCAN_COMMENTS_ONLY, oldVal, val );
160
public void addPropertyChangeListener( PropertyChangeListener l ) {
161
if( null == propertySupport )
162
propertySupport = new PropertyChangeSupport( this );
163
propertySupport.addPropertyChangeListener( l );
166
public void removePropertyChangeListener( PropertyChangeListener l ) {
167
if( null != propertySupport )
168
propertySupport.removePropertyChangeListener( l );
171
private Preferences getPreferences() {
172
return NbPreferences.forModule( Settings.class );
175
private static Collection<String> decodePatterns( String encodedPatterns ) {
176
StringTokenizer st = new StringTokenizer( encodedPatterns, PATTERN_DELIMITER, false );
178
Collection<String> patterns = new ArrayList<String>();
180
while( st.hasMoreTokens() ) {
181
String im = st.nextToken();
188
private static String encodePatterns( Collection<String> patterns ) {
189
StringBuffer sb = new StringBuffer();
191
for( String p : patterns ) {
193
sb.append( PATTERN_DELIMITER );
196
return sb.toString();
199
private static class CommentTags {
200
private String lineComment;
201
private String blockCommentStart;
202
private String blockCommentEnd;
204
public CommentTags( String lineComment, String blockCommentStart, String blockCommentEnd ) {
205
this.lineComment = lineComment;
206
this.blockCommentStart = blockCommentStart;
207
this.blockCommentEnd = blockCommentEnd;
210
public CommentTags( String blockCommentStart, String blockCommentEnd ) {
211
this.blockCommentStart = blockCommentStart;
212
this.blockCommentEnd = blockCommentEnd;
215
public CommentTags( String lineComment ) {
216
this.lineComment = lineComment;