|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| package net.sourceforge.astyleclipse.astyle; |
|
28 |
| |
|
29 |
| |
|
30 |
| import java.beans.*; |
|
31 |
| import java.lang.reflect.*; |
|
32 |
| import java.util.Locale; |
|
33 |
| import java.util.ResourceBundle; |
|
34 |
| import java.util.Vector; |
|
35 |
| |
|
36 |
| |
|
37 |
| public class ASFormatterBeanInfo extends SimpleBeanInfo { |
|
38 |
| |
|
39 |
0
| public ASFormatterBeanInfo() {
|
|
40 |
0
| super();
|
|
41 |
0
| propertyDescriptors = new Vector();
|
|
42 |
0
| resources = ResourceBundle.getBundle("astyle.ASFormatterBeanInfoTexts");
|
|
43 |
| |
|
44 |
| |
|
45 |
0
| addPropertyDescription("blockIndent");
|
|
46 |
0
| addPropertyDescription("bracketIndent");
|
|
47 |
0
| addPropertyDescription("caseIndent");
|
|
48 |
0
| addPropertyDescription("classIndent");
|
|
49 |
0
| addPropertyDescription("cStyle");
|
|
50 |
0
| addPropertyDescription("emptyLineFill");
|
|
51 |
0
| addPropertyDescription("forceTabs");
|
|
52 |
0
| addPropertyDescription("labelIndent");
|
|
53 |
0
| addPropertyDescription("maxInStatementIndentLength");
|
|
54 |
0
| addPropertyDescription("minConditionalIndentLength");
|
|
55 |
0
| addPropertyDescription("namespaceIndent");
|
|
56 |
0
| addPropertyDescription("preprocessorIndent");
|
|
57 |
0
| addPropertyDescription("spaceIndentation");
|
|
58 |
0
| addPropertyDescription("switchIndent");
|
|
59 |
0
| addPropertyDescription("tabIndentation");
|
|
60 |
0
| addPropertyDescription("useTabs");
|
|
61 |
| |
|
62 |
| |
|
63 |
0
| addPropertyDescription("bracketFormatMode", BracketFormatModePropertyEditor.class);
|
|
64 |
0
| addPropertyDescription("breakBlocksMode");
|
|
65 |
0
| addPropertyDescription("breakClosingHeaderBlocksMode");
|
|
66 |
0
| addPropertyDescription("breakClosingHeaderBracketsMode");
|
|
67 |
0
| addPropertyDescription("breakElseIfsMode");
|
|
68 |
0
| addPropertyDescription("breakOneLineBlocksMode");
|
|
69 |
0
| addPropertyDescription("operatorPaddingMode");
|
|
70 |
0
| addPropertyDescription("parenthesisPaddingMode");
|
|
71 |
0
| addPropertyDescription("singleStatementsMode");
|
|
72 |
0
| addPropertyDescription("tabSpaceConversionMode");
|
|
73 |
| } |
|
74 |
| |
|
75 |
| |
|
76 |
0
| public BeanDescriptor getBeanDescriptor() {
|
|
77 |
0
| return new BeanDescriptor(ASFormatter.class);
|
|
78 |
| } |
|
79 |
| |
|
80 |
| |
|
81 |
0
| public PropertyDescriptor[] getPropertyDescriptors() {
|
|
82 |
0
| PropertyDescriptor[] pds = new PropertyDescriptor[propertyDescriptors.size()];
|
|
83 |
0
| propertyDescriptors.copyInto(pds);
|
|
84 |
0
| return pds;
|
|
85 |
| } |
|
86 |
| |
|
87 |
| |
|
88 |
0
| protected void addPropertyDescription(String name, String displayName, String description, Class propertyEditorClass, Class beanClass) {
|
|
89 |
0
| try {
|
|
90 |
0
| PropertyDescriptor pd = new PropertyDescriptor(name, beanClass);
|
|
91 |
0
| pd.setDisplayName(displayName);
|
|
92 |
0
| pd.setShortDescription(description);
|
|
93 |
0
| if (propertyEditorClass != null)
|
|
94 |
0
| pd.setPropertyEditorClass(propertyEditorClass);
|
|
95 |
0
| propertyDescriptors.addElement(pd);
|
|
96 |
| } |
|
97 |
| catch (IntrospectionException e) { |
|
98 |
0
| System.err.println(e);
|
|
99 |
| } |
|
100 |
| } |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
| |
|
105 |
| |
|
106 |
| |
|
107 |
| |
|
108 |
0
| protected void removePropertyDescription(final String name) {
|
|
109 |
0
| for (int i = propertyDescriptors.size() - 1; i >= 0; --i) {
|
|
110 |
0
| PropertyDescriptor pd = (PropertyDescriptor) propertyDescriptors.elementAt(i);
|
|
111 |
0
| if (name.equals(pd.getName())) {
|
|
112 |
0
| propertyDescriptors.removeElementAt(i);
|
|
113 |
0
| return;
|
|
114 |
| } |
|
115 |
| } |
|
116 |
| } |
|
117 |
| |
|
118 |
| |
|
119 |
0
| private void addPropertyDescription(String key, Class propertyEditorClass) {
|
|
120 |
0
| addPropertyDescription(
|
|
121 |
| key, |
|
122 |
| resources.getString(key + ".label"), |
|
123 |
| resources.getString(key + ".description"), |
|
124 |
| propertyEditorClass, |
|
125 |
| ASFormatter.class |
|
126 |
| ); |
|
127 |
| } |
|
128 |
| |
|
129 |
| |
|
130 |
0
| private void addPropertyDescription(String key) {
|
|
131 |
0
| addPropertyDescription(key, null);
|
|
132 |
| } |
|
133 |
| |
|
134 |
| |
|
135 |
| protected Vector propertyDescriptors; |
|
136 |
| protected ResourceBundle resources; |
|
137 |
| |
|
138 |
| |
|
139 |
| private static final String[] bracketTypeTags = new String[4]; |
|
140 |
| |
|
141 |
| |
|
142 |
| static { |
|
143 |
0
| bracketTypeTags[ASResource.BREAK_MODE] = "ANSI C/C++";
|
|
144 |
0
| bracketTypeTags[ASResource.ATTACH_MODE] = "Java / K&R";
|
|
145 |
0
| bracketTypeTags[ASResource.BDAC_MODE] = "Linux";
|
|
146 |
0
| bracketTypeTags[ASResource.NONE_MODE] = "None";
|
|
147 |
| } |
|
148 |
| |
|
149 |
| |
|
150 |
| public static class BracketFormatModePropertyEditor extends PropertyEditorSupport { |
|
151 |
| |
|
152 |
0
| public BracketFormatModePropertyEditor() {
|
|
153 |
0
| super();
|
|
154 |
| } |
|
155 |
| |
|
156 |
| |
|
157 |
0
| public String[] getTags() {
|
|
158 |
0
| return bracketTypeTags;
|
|
159 |
| } |
|
160 |
| |
|
161 |
| |
|
162 |
0
| public String getAsText() {
|
|
163 |
0
| return bracketTypeTags[((Integer)getValue()).intValue()];
|
|
164 |
| } |
|
165 |
| |
|
166 |
| |
|
167 |
0
| public void setAsText(String text) {
|
|
168 |
0
| for (int i = 0; i < 4; ++i) {
|
|
169 |
0
| if (bracketTypeTags[i].equals(text)) {
|
|
170 |
0
| setValue(new Integer(i));
|
|
171 |
0
| return;
|
|
172 |
| } |
|
173 |
| } |
|
174 |
0
| throw new IllegalArgumentException("illegal text value: " + text);
|
|
175 |
| } |
|
176 |
| |
|
177 |
| } |
|
178 |
| |
|
179 |
| } |