Clover coverage report - PMD - 3.9 Coverage timestamp: Tue Dec 19 2006 09:38:44 EST FRAMES NO FRAMES |
file stats: | LOC: | 143 |  | Methods: | 3
| NCLOC: | 115 |  | Classes: | 1
Source file | Conditionals | Statements | Methods | TOTAL
CreateXMLRulePanel.java | 0% | 0% | 0% | 0% |

1 |  | package net.sourceforge.pmd.util.designer;
2 |  |
3 |  | import java.awt.GridBagConstraints;
4 |  | import java.awt.GridBagLayout;
5 |  | import java.awt.event.ActionEvent;
6 |  | import java.awt.event.ActionListener;
7 |  |
8 |  | import javax.swing.JButton;
9 |  | import javax.swing.JLabel;
10 |  | import javax.swing.JPanel;
11 |  | import javax.swing.JScrollPane;
12 |  | import javax.swing.JTextArea;
13 |  | import javax.swing.JTextField;
14 |  |
15 |  | import net.sourceforge.pmd.PMD;
16 |  |
17 |  | /**
18 |  | * This class is responsible for creating the
19 |  | * contentpanel for the Create Rule XML Frame.
20 |  | */
21 |  | public class CreateXMLRulePanel extends JPanel implements ActionListener{
22 |  |
23 |  | private JTextField rulenameField = new JTextField(30);
24 |  | private JTextField rulemsgField = new JTextField(30);
25 |  | private JTextArea ruledescField = new JTextArea(5,30);
26 |  | private JTextArea ruleXMLArea = new JTextArea(30, 30);
27 |  | private JTextArea xpathQueryArea = new JTextArea();
28 |  | private CodeEditorTextPane codeEditorPane = new CodeEditorTextPane();
29 |  |
30 | 0 | public CreateXMLRulePanel(JTextArea xpathQueryArea, CodeEditorTextPane codeEditorPane){
31 | 0 | super();
32 | 0 | this.xpathQueryArea = xpathQueryArea;
33 | 0 | this.codeEditorPane = codeEditorPane;
34 | 0 | GridBagConstraints gbc = new GridBagConstraints();
35 |  | // We use a gridbaglayout for a nice and sturdy look and feel
36 | 0 | GridBagLayout gbl = new GridBagLayout();
37 | 0 | setLayout(gbl);
38 |  |
39 | 0 | gbc.gridx = 0;
40 | 0 | gbc.gridy = 0;
41 | 0 | gbc.fill = GridBagConstraints.NONE;
42 | 0 | gbc.anchor = GridBagConstraints.EAST;
43 | 0 | gbc.weightx = 0.5;
44 | 0 | JLabel rulenameLabel = new JLabel("Rule name : ");
45 | 0 | gbl.setConstraints(rulenameLabel, gbc);
46 | 0 | add(rulenameLabel);
47 | 0 | gbc.weightx = 0.5;
48 | 0 | gbc.anchor = GridBagConstraints.WEST;
49 | 0 | gbc.gridx = 1;
50 | 0 | gbl.setConstraints(rulenameField, gbc);
51 | 0 | add(rulenameField);
52 |  |
53 | 0 | gbc.gridx = 0;
54 | 0 | gbc.gridy = 1;
55 | 0 | gbc.anchor = GridBagConstraints.EAST;
56 | 0 | gbc.weightx = 0.5;
57 | 0 | JLabel rulemsgLabel = new JLabel("Rule msg : ");
58 | 0 | gbl.setConstraints(rulemsgLabel, gbc);
59 | 0 | add(rulemsgLabel);
60 | 0 | gbc.gridx = 1;
61 | 0 | gbc.anchor = GridBagConstraints.WEST;
62 | 0 | gbc.weightx = 0.5;
63 | 0 | gbl.setConstraints(rulemsgField, gbc);
64 | 0 | add(rulemsgField);
65 |  |
66 | 0 | gbc.gridx = 0;
67 | 0 | gbc.gridy = 2;
68 | 0 | gbc.anchor = GridBagConstraints.EAST;
69 | 0 | gbc.weightx = 0.5;
70 | 0 | JLabel ruledescLabel = new JLabel("Rule desc : ");
71 | 0 | gbl.setConstraints(ruledescLabel,gbc);
72 | 0 | add(ruledescLabel);
73 | 0 | gbc.gridx = 1;
74 | 0 | gbc.anchor = GridBagConstraints.WEST;
75 | 0 | gbc.weightx = 0.5;
76 | 0 | gbl.setConstraints(ruledescField,gbc);
77 | 0 | add(ruledescField);
78 |  |
79 | 0 | gbc.gridx = 0;
80 | 0 | gbc.gridy = 3;
81 | 0 | gbc.gridwidth = 2;
82 | 0 | gbc.anchor = GridBagConstraints.NORTH;
83 | 0 | JButton createRuleBtn = new JButton("Create rule XML");
84 | 0 | createRuleBtn.addActionListener(this);
85 | 0 | gbl.setConstraints(createRuleBtn, gbc);
86 | 0 | add(createRuleBtn);
87 |  |
88 | 0 | gbc.gridx = 0;
89 | 0 | gbc.gridy = 4;
90 | 0 | gbc.anchor = GridBagConstraints.NORTH;
91 | 0 | gbc.fill = GridBagConstraints.BOTH;
92 | 0 | gbc.weightx = 1.0;
93 | 0 | gbc.weighty = 1.0;
94 | 0 | JScrollPane ruleXMLPane = new JScrollPane(ruleXMLArea);
95 | 0 | gbl.setConstraints(ruleXMLPane, gbc);
96 | 0 | add(ruleXMLPane);
97 |  |
98 | 0 | repaint();
99 |  | }
100 |  |
101 | 0 | private void appendLn(StringBuffer sb, String text) {
102 | 0 | sb.append(text).append(PMD.EOL);
103 |  | }
104 |  |
105 |  | /**
106 |  | * We let our class implement the ActionListener interface
107 |  | * and use it to generate the xml code when the user presses
108 |  | * the "Create rule XML" button.
109 |  | *
110 |  | */
111 | 0 | public void actionPerformed(ActionEvent exception) {
112 | 0 | StringBuffer buffer = new StringBuffer(200);
113 | 0 | appendLn(buffer, "<rule name=\"" + rulenameField.getText() + '\"');
114 | 0 | appendLn(buffer, " message=\"" + rulemsgField.getText() + '\"');
115 | 0 | appendLn(buffer, " class=\"" + (xpathQueryArea.getText().length() == 0 ? "" : "net.sourceforge.pmd.rules.XPathRule") + "\">");
116 | 0 | appendLn(buffer, " <description>");
117 | 0 | appendLn(buffer, " " + ruledescField.getText());
118 | 0 | appendLn(buffer, " </description>");
119 | 0 | if (xpathQueryArea.getText().length() != 0) {
120 | 0 | appendLn(buffer, " <properties>");
121 | 0 | appendLn(buffer, " <property name=\"xpath\">");
122 | 0 | appendLn(buffer, " <value>");
123 | 0 | appendLn(buffer, "<![CDATA[");
124 | 0 | appendLn(buffer, xpathQueryArea.getText());
125 | 0 | appendLn(buffer, "]]>");
126 | 0 | appendLn(buffer, " </value>");
127 | 0 | appendLn(buffer, " </property>");
128 | 0 | appendLn(buffer, " </properties>");
129 |  | }
130 | 0 | appendLn(buffer, " <priority>3</priority>");
131 | 0 | appendLn(buffer, " <example>");
132 | 0 | appendLn(buffer, "<![CDATA[");
133 | 0 | appendLn(buffer, codeEditorPane.getText());
134 | 0 | appendLn(buffer, "]]>");
135 | 0 | appendLn(buffer, " </example>");
136 | 0 | appendLn(buffer, "</rule>");
137 |  |
138 | 0 | ruleXMLArea.setText(buffer.toString());
139 | 0 | repaint();
140 |  | }
141 |  |
142 |  | }
143 |  |