KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > gui2 > NewFilterFromBug


1 /*
2  * FindBugs - Find Bugs in Java programs
3  * Copyright (C) 2006, University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307, USA
18  */

19
20 package edu.umd.cs.findbugs.gui2;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.HashMap JavaDoc;
27 import java.util.List JavaDoc;
28
29 import javax.swing.Box JavaDoc;
30 import javax.swing.BoxLayout JavaDoc;
31 import javax.swing.ButtonGroup JavaDoc;
32 import javax.swing.JButton JavaDoc;
33 import javax.swing.JFrame JavaDoc;
34 import javax.swing.JLabel JavaDoc;
35 import javax.swing.JPanel JavaDoc;
36 import javax.swing.JRadioButton JavaDoc;
37 import javax.swing.tree.TreeModel JavaDoc;
38
39 import edu.umd.cs.findbugs.BugInstance;
40
41 /**
42  * Allows you to make a new Filter by right clicking (control clicking) on a bug in the tree
43  */

44 @SuppressWarnings JavaDoc("serial")
45 public class NewFilterFromBug extends FBDialog
46 {
47     private HashMap JavaDoc<JRadioButton JavaDoc, Sortables> map = new HashMap JavaDoc<JRadioButton JavaDoc, Sortables>();
48     private JRadioButton JavaDoc selectedRadioButton = null;
49     static List JavaDoc<NewFilterFromBug> listOfAllFrames=new ArrayList JavaDoc<NewFilterFromBug>();
50     
51     public NewFilterFromBug(final BugInstance bug)
52     {
53         this.setModal(true);
54         listOfAllFrames.add(this);
55         setLayout(new BorderLayout JavaDoc());
56         add(new JLabel JavaDoc("Filter out all bugs whose..."), BorderLayout.NORTH);
57         
58         JPanel JavaDoc center = new JPanel JavaDoc();
59         center.setLayout(new BoxLayout JavaDoc(center, BoxLayout.Y_AXIS));
60         ButtonGroup JavaDoc group = new ButtonGroup JavaDoc();
61         for (Sortables s : Sortables.values())
62         {
63             if (s.equals(Sortables.DIVIDER))
64                 continue;
65             JRadioButton JavaDoc radio = new JRadioButton JavaDoc(s.toString() + " is " + s.formatValue(s.getFrom(bug)));
66             radio.addActionListener(new ActionListener JavaDoc() {
67                 public void actionPerformed(ActionEvent JavaDoc evt)
68                 {
69                     selectedRadioButton = (JRadioButton JavaDoc) evt.getSource();
70                 }
71             });
72             map.put(radio, s);
73             group.add(radio);
74             center.add(radio);
75         }
76         add(center, BorderLayout.CENTER);
77         
78         JPanel JavaDoc south = new JPanel JavaDoc();
79         JButton JavaDoc okButton = new JButton JavaDoc("OK");
80         okButton.addActionListener(new ActionListener JavaDoc()
81         {
82             public void actionPerformed(ActionEvent JavaDoc evt)
83             {
84                 if (selectedRadioButton != null)
85                 {
86                     FilterMatcher newFilter=new FilterMatcher(map.get(selectedRadioButton), map.get(selectedRadioButton).getFrom(bug));
87                     ArrayList JavaDoc<FilterMatcher> filters=ProjectSettings.getInstance().getAllFilters();
88                     if (!filters.contains(newFilter))
89                     {
90                         ProjectSettings.getInstance().addFilter(newFilter);
91                     }
92                     else //if filter is already there, turn it on
93
{
94                         filters.get(filters.indexOf(newFilter)).setActive(true);
95                     }
96                     PreferencesFrame.getInstance().updateFilterPanel();
97                     NewFilterFromBug.this.dispose();
98                 }
99             }
100         });
101         JButton JavaDoc cancelButton = new JButton JavaDoc("Cancel");
102         cancelButton.addActionListener(new ActionListener JavaDoc()
103         {
104             public void actionPerformed(ActionEvent JavaDoc evt)
105             {
106                 NewFilterFromBug.this.dispose();
107             }
108         });
109         south.setLayout(new BoxLayout JavaDoc(south, BoxLayout.X_AXIS));
110         south.add(Box.createHorizontalGlue());
111         south.add(okButton);
112         south.add(Box.createHorizontalStrut(5));
113         south.add(cancelButton);
114         add(south, BorderLayout.SOUTH);
115         
116         pack();
117         setVisible(true);
118     }
119     
120     static void closeAll()
121     {
122         for(NewFilterFromBug frame: listOfAllFrames)
123             frame.dispose();
124         listOfAllFrames.clear();
125     }
126 }
127
Popular Tags