1 19 20 package org.netbeans.modules.editor.java; 21 22 import java.io.*; 23 import javax.swing.text.Document ; 24 import org.netbeans.editor.ext.ExtFormatter; 25 import org.netbeans.editor.ext.java.JavaFormatter; 26 import org.netbeans.editor.ext.java.JavaSettingsNames; 27 import org.netbeans.editor.ext.java.JavaSettingsDefaults; 28 import org.netbeans.modules.editor.EditorModule; 29 import org.netbeans.modules.editor.FormatterIndentEngine; 30 import org.openide.text.IndentEngine; 31 32 37 38 public class JavaIndentEngine extends FormatterIndentEngine { 39 40 public static final String JAVA_FORMAT_NEWLINE_BEFORE_BRACE_PROP 41 = "javaFormatNewlineBeforeBrace"; 43 public static final String JAVA_FORMAT_SPACE_BEFORE_PARENTHESIS_PROP 44 = "javaFormatSpaceBeforeParenthesis"; 46 public static final String JAVA_FORMAT_LEADING_STAR_IN_COMMENT_PROP 47 = "javaFormatLeadingStarInComment"; 49 public static final String JAVA_FORMAT_STATEMENT_CONTINUATION_INDENT_PROP 50 = "javaFormatStatementContinuationIndent"; 52 static final long serialVersionUID = -7936605291288152329L; 53 54 public JavaIndentEngine() { 55 setAcceptedMimeTypes(new String [] { JavaKit.JAVA_MIME_TYPE }); 56 } 57 58 protected ExtFormatter createFormatter() { 59 return new JavaFormatter(JavaKit.class); 60 } 61 62 63 public boolean getJavaFormatSpaceBeforeParenthesis() { 64 Boolean b = (Boolean )getValue(JavaSettingsNames.JAVA_FORMAT_SPACE_BEFORE_PARENTHESIS); 65 if (b == null) { 66 b = JavaSettingsDefaults.defaultJavaFormatSpaceBeforeParenthesis; 67 } 68 return b.booleanValue(); 69 } 70 public void setJavaFormatSpaceBeforeParenthesis(boolean b) { 71 setValue(JavaSettingsNames.JAVA_FORMAT_SPACE_BEFORE_PARENTHESIS, b ? Boolean.TRUE : Boolean.FALSE, JAVA_FORMAT_SPACE_BEFORE_PARENTHESIS_PROP); 72 } 73 74 public boolean getJavaFormatNewlineBeforeBrace() { 75 Boolean b = (Boolean )getValue(JavaSettingsNames.JAVA_FORMAT_NEWLINE_BEFORE_BRACE); 76 if (b == null) { 77 b = JavaSettingsDefaults.defaultJavaFormatNewlineBeforeBrace; 78 } 79 return b.booleanValue(); 80 } 81 public void setJavaFormatNewlineBeforeBrace(boolean b) { 82 setValue(JavaSettingsNames.JAVA_FORMAT_NEWLINE_BEFORE_BRACE, b ? Boolean.TRUE : Boolean.FALSE, JAVA_FORMAT_NEWLINE_BEFORE_BRACE_PROP); 83 } 84 85 public boolean getJavaFormatLeadingStarInComment() { 86 Boolean b = (Boolean )getValue(JavaSettingsNames.JAVA_FORMAT_LEADING_STAR_IN_COMMENT); 87 if (b == null) { 88 b = JavaSettingsDefaults.defaultJavaFormatLeadingStarInComment; 89 } 90 return b.booleanValue(); 91 } 92 public void setJavaFormatLeadingStarInComment(boolean b) { 93 setValue(JavaSettingsNames.JAVA_FORMAT_LEADING_STAR_IN_COMMENT, b ? Boolean.TRUE : Boolean.FALSE, JAVA_FORMAT_LEADING_STAR_IN_COMMENT_PROP); 94 } 95 96 public int getJavaFormatStatementContinuationIndent() { 97 Integer i = (Integer )getValue(JavaSettingsNames.JAVA_FORMAT_STATEMENT_CONTINUATION_INDENT); 98 if (i == null) { 99 i = JavaSettingsDefaults.defaultJavaFormatStatementContinuationIndent; 100 } 101 return i.intValue(); 102 } 103 104 public void setJavaFormatStatementContinuationIndent(int javaFormatStatementContinuationIndent) { 105 setValue(JavaSettingsNames.JAVA_FORMAT_STATEMENT_CONTINUATION_INDENT, 106 new Integer (javaFormatStatementContinuationIndent), JAVA_FORMAT_STATEMENT_CONTINUATION_INDENT_PROP); 107 } 108 109 111 private static final ObjectStreamField[] serialPersistentFields = { 112 new ObjectStreamField(JAVA_FORMAT_NEWLINE_BEFORE_BRACE_PROP, Boolean.TYPE), 113 new ObjectStreamField(JAVA_FORMAT_SPACE_BEFORE_PARENTHESIS_PROP, Boolean.TYPE), 114 new ObjectStreamField(JAVA_FORMAT_LEADING_STAR_IN_COMMENT_PROP, Boolean.TYPE), 115 new ObjectStreamField(JAVA_FORMAT_STATEMENT_CONTINUATION_INDENT_PROP, Integer.TYPE) 116 }; 117 118 private void readObject(java.io.ObjectInputStream ois) 119 throws IOException, ClassNotFoundException { 120 ObjectInputStream.GetField fields = ois.readFields(); 121 setJavaFormatNewlineBeforeBrace(fields.get(JAVA_FORMAT_NEWLINE_BEFORE_BRACE_PROP, 122 getJavaFormatNewlineBeforeBrace())); 123 setJavaFormatSpaceBeforeParenthesis(fields.get(JAVA_FORMAT_SPACE_BEFORE_PARENTHESIS_PROP, 124 getJavaFormatSpaceBeforeParenthesis())); 125 setJavaFormatLeadingStarInComment(fields.get(JAVA_FORMAT_LEADING_STAR_IN_COMMENT_PROP, 126 getJavaFormatLeadingStarInComment())); 127 setJavaFormatStatementContinuationIndent(fields.get(JAVA_FORMAT_STATEMENT_CONTINUATION_INDENT_PROP, 128 getJavaFormatStatementContinuationIndent())); 129 } 130 131 private void writeObject(java.io.ObjectOutputStream oos) 132 throws IOException, ClassNotFoundException { 133 ObjectOutputStream.PutField fields = oos.putFields(); 134 fields.put(JAVA_FORMAT_NEWLINE_BEFORE_BRACE_PROP, getJavaFormatNewlineBeforeBrace()); 135 fields.put(JAVA_FORMAT_SPACE_BEFORE_PARENTHESIS_PROP, getJavaFormatSpaceBeforeParenthesis()); 136 fields.put(JAVA_FORMAT_LEADING_STAR_IN_COMMENT_PROP, getJavaFormatLeadingStarInComment()); 137 fields.put(JAVA_FORMAT_STATEMENT_CONTINUATION_INDENT_PROP, getJavaFormatStatementContinuationIndent()); 138 oos.writeFields(); 139 } 140 141 } 142 143 | Popular Tags |