Source Code Cross Referenced for SelectedRules.java in  » UML » jrefactory » org » acm » seguin » ide » common » options » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » UML » jrefactory » org.acm.seguin.ide.common.options 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  User: tom
003:         *  Date: Jul 9, 2002
004:         *  Time: 1:18:38 PM
005:         */
006:        package org.acm.seguin.ide.common.options;
007:
008:        import java.util.Comparator;
009:        import java.util.Iterator;
010:        import java.util.Map;
011:        import java.util.StringTokenizer;
012:        import java.util.TreeMap;
013:        import java.util.Set;
014:        import java.util.HashSet;
015:
016:        import javax.swing.JCheckBox;
017:        import javax.swing.JOptionPane;
018:        import org.acm.seguin.ide.common.IDEPlugin;
019:
020:        import org.acm.seguin.ide.common.options.PropertiesFile;
021:
022:        import org.acm.seguin.pmd.Rule;
023:        import org.acm.seguin.pmd.RuleSet;
024:        import org.acm.seguin.pmd.RuleSetFactory;
025:        import org.acm.seguin.pmd.RuleSetNotFoundException;
026:
027:        /**
028:         *  Description of the Class
029:         *
030:         *@author     jiger.p
031:         *@created    April 22, 2003
032:         */
033:        public class SelectedRules {
034:
035:            private static Set notFoundRulesets = new HashSet();
036:            // Rule -> JCheckBox
037:            private Map defaultRules = null;
038:            private Map rules = new TreeMap(new Comparator() {
039:                public int compare(Object o1, Object o2) {
040:                    Rule r1 = (Rule) o1;
041:                    Rule r2 = (Rule) o2;
042:                    return r1.getName().compareTo(r2.getName());
043:                }
044:            });
045:
046:            private PropertiesFile props;
047:
048:            /**
049:             *  Constructor for the SelectedRules object
050:             *
051:             *@param  project                       Description of Parameter
052:             *@param  parent                        Description of Parameter
053:             *@exception  RuleSetNotFoundException  Description of the Exception
054:             */
055:            public SelectedRules(String project, java.awt.Component parent)
056:                    throws RuleSetNotFoundException {
057:                if ("default".equals(project)) {
058:                    notFoundRulesets = new HashSet();
059:                } else {
060:                    if (defaultRules != null) {
061:                        rules.putAll(defaultRules);
062:                    }
063:                }
064:
065:                props = IDEPlugin.getProperties("pmd", project);
066:                RuleSetFactory rsf = new RuleSetFactory();
067:                for (Iterator i = rsf.getRegisteredRuleSets(); i.hasNext();) {
068:                    addRuleSet2Rules((RuleSet) i.next());
069:                }
070:
071:                //Load project modified RuleSets if any.
072:                java.io.File dir = org.acm.seguin.util.FileSettings
073:                        .getRefactorySettingsRoot();
074:                dir = new java.io.File(dir, "projects");
075:                dir = new java.io.File(dir, project);
076:                if (dir.exists()) {
077:                    dir = new java.io.File(dir, "rules");
078:                    if (!dir.exists()) {
079:                        dir.mkdir();
080:                    }
081:                    java.io.File[] files = dir.listFiles();
082:                    for (int i = 0; i < files.length; i++) {
083:                        try {
084:                            String rulesetName = files[i].getCanonicalPath();
085:                            if (rulesetName.toLowerCase().endsWith(".xml")) {
086:                                addRuleSet2Rules(rsf
087:                                        .createRuleSet(new java.io.FileInputStream(
088:                                                files[i])));
089:                            }
090:                        } catch (Exception e) {
091:                            e.printStackTrace();
092:                        }
093:                    }
094:                }
095:
096:                //Load custom RuleSets if any.
097:                if (props.isLocalProperty("pmd.path")) {
098:                    String customRuleSetPath = props.getString("pmd.path");
099:                    if (!(customRuleSetPath == null)) {
100:                        StringTokenizer strtok = new StringTokenizer(
101:                                customRuleSetPath, ",");
102:                        while (strtok.hasMoreTokens()) {
103:                            String rulesetName = strtok.nextToken();
104:                            if (rulesetName != null
105:                                    && !rulesetName.equals("<none>")) {
106:                                try {
107:                                    addRuleSet2Rules(rsf
108:                                            .createRuleSet(rulesetName));
109:                                } catch (Exception e) {
110:                                    if (notFoundRulesets.add(rulesetName)) {
111:                                        e.printStackTrace();
112:                                        JOptionPane.showMessageDialog(parent,
113:                                                "Can't load custom ruleset \""
114:                                                        + rulesetName + "\"",
115:                                                "JavaStyle",
116:                                                JOptionPane.ERROR_MESSAGE);
117:                                    }
118:                                }
119:                            }
120:                        }
121:                    }
122:                }
123:                if ("default".equals(project)) {
124:                    defaultRules = rules;
125:                }
126:            }
127:
128:            /**
129:             *  Gets the rule attribute of the SelectedRules object
130:             *
131:             *@param  candidate  Description of the Parameter
132:             *@return            The rule value
133:             */
134:            public Rule getRule(JCheckBox candidate) {
135:                for (Iterator i = rules.keySet().iterator(); i.hasNext();) {
136:                    Rule rule = (Rule) i.next();
137:                    JCheckBox box = (JCheckBox) rules.get(rule);
138:                    if (box.equals(candidate)) {
139:                        return rule;
140:                    }
141:                }
142:                throw new RuntimeException(
143:                        "Couldn't find a rule that mapped to the passed in JCheckBox "
144:                                + candidate);
145:            }
146:
147:            /**
148:             *  Description of the Method
149:             *
150:             *@param  key  Description of the Parameter
151:             *@return      Description of the Return Value
152:             */
153:            public JCheckBox get(Object key) {
154:                return (JCheckBox) rules.get(key);
155:            }
156:
157:            /**
158:             *  Gets the allBoxes attribute of the SelectedRules object
159:             *
160:             *@return    The allBoxes value
161:             */
162:            public Object[] getAllBoxes() {
163:                Object[] foo = new Object[rules.size()];
164:                int idx = 0;
165:                for (Iterator i = rules.values().iterator(); i.hasNext();) {
166:                    foo[idx] = i.next();
167:                    idx++;
168:                }
169:                return foo;
170:            }
171:
172:            /**
173:             *  Gets the selectedRules attribute of the SelectedRules object
174:             *
175:             *@return    The selectedRules value
176:             */
177:            public RuleSet getSelectedRules() {
178:                RuleSet newRuleSet = new RuleSet();
179:                for (Iterator i = rules.keySet().iterator(); i.hasNext();) {
180:                    Rule rule = (Rule) i.next();
181:                    if (get(rule).isSelected()) {
182:                        newRuleSet.addRule(rule);
183:                    }
184:                }
185:                return newRuleSet;
186:            }
187:
188:            /**
189:             *  Description of the Method
190:             *
191:             *@return    Description of the Return Value
192:             */
193:            public int size() {
194:                return rules.size();
195:            }
196:
197:            /**  Description of the Method */
198:            public void save() {
199:                for (Iterator i = rules.keySet().iterator(); i.hasNext();) {
200:                    Rule rule = (Rule) i.next();
201:                    props.setString(rule.getName(), Boolean.toString(get(rule)
202:                            .isSelected()));
203:                }
204:                props.save();
205:            }
206:
207:            /**
208:             *  Description of the Method
209:             *
210:             *@param  name  Description of the Parameter
211:             *@return       Description of the Return Value
212:             */
213:            private JCheckBox createCheckBox(String name) {
214:                JCheckBox box = new JCheckBox(name);
215:                try {
216:                    box.setSelected(props.getBoolean(name));
217:                } catch (Exception e) {
218:                    box.setSelected(true);
219:                }
220:                return box;
221:            }
222:
223:            /**
224:             *  Adds a feature to the RuleSet2Rules attribute of the SelectedRules object
225:             *
226:             *@param  rs  The feature to be added to the RuleSet2Rules attribute
227:             */
228:            private void addRuleSet2Rules(RuleSet rs) {
229:                for (Iterator j = rs.getRules().iterator(); j.hasNext();) {
230:                    Rule rule = (Rule) j.next();
231:                    rules.remove(rule); // FIXME? this shouldn't be necessary?!?!
232:                    rules.put(rule, createCheckBox(rule.getName()));
233:                }
234:            }
235:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.