001: /*
002: * FindBugs - Find Bugs in Java programs
003: * Copyright (C) 2006, University of Maryland
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307, USA
018: */
019:
020: package edu.umd.cs.findbugs.gui2;
021:
022: import java.awt.BorderLayout;
023: import java.awt.event.ActionEvent;
024: import java.awt.event.ActionListener;
025: import java.util.ArrayList;
026: import java.util.HashMap;
027: import java.util.HashSet;
028: import java.util.List;
029: import java.util.Map;
030:
031: import javax.swing.BoxLayout;
032: import javax.swing.JButton;
033: import javax.swing.JCheckBox;
034: import javax.swing.JLabel;
035: import javax.swing.JPanel;
036:
037: import edu.umd.cs.findbugs.BugInstance;
038: import edu.umd.cs.findbugs.filter.Filter;
039: import edu.umd.cs.findbugs.filter.Matcher;
040:
041: /**
042: * Allows you to make a new Filter by right clicking (control clicking) on a bug in the tree
043: */
044: @SuppressWarnings("serial")
045: public class NewFilterFromBug extends FBDialog {
046: private HashMap<JCheckBox, Sortables> map = new HashMap<JCheckBox, Sortables>();
047: static List<NewFilterFromBug> listOfAllFrames = new ArrayList<NewFilterFromBug>();
048:
049: public NewFilterFromBug(final BugInstance bug) {
050: this .setModal(true);
051: listOfAllFrames.add(this );
052: setLayout(new BorderLayout());
053: add(new JLabel("Filter out all bugs whose..."),
054: BorderLayout.NORTH);
055:
056: JPanel center = new JPanel();
057: center.setLayout(new BoxLayout(center, BoxLayout.Y_AXIS));
058: for (Sortables s : Sortables.values()) {
059: if (s.equals(Sortables.DIVIDER))
060: continue;
061: JCheckBox radio = new JCheckBox(s.toString() + " is "
062: + s.formatValue(s.getFrom(bug)));
063:
064: map.put(radio, s);
065: center.add(radio);
066: }
067: add(center, BorderLayout.CENTER);
068:
069: JPanel south = new JPanel();
070: JButton okButton = new JButton(edu.umd.cs.findbugs.L10N
071: .getLocalString("dlg.ok_btn", "OK"));
072: okButton.addActionListener(new ActionListener() {
073: public void actionPerformed(ActionEvent evt) {
074: HashSet<Sortables> set = new HashSet<Sortables>();
075: for (Map.Entry<JCheckBox, Sortables> e : map.entrySet()) {
076: if (e.getKey().isSelected())
077: set.add(e.getValue());
078: }
079: if (!set.isEmpty()) {
080: Matcher m = FilterFactory.makeMatcher(set, bug);
081: Filter f = MainFrame.getInstance().getProject()
082: .getSuppressionFilter();
083:
084: f.addChild(m);
085:
086: PreferencesFrame.getInstance().updateFilterPanel();
087: FilterActivity.notifyListeners(
088: FilterListener.Action.FILTERING, null);
089: NewFilterFromBug.this .dispose();
090: }
091: }
092: });
093: JButton cancelButton = new JButton(edu.umd.cs.findbugs.L10N
094: .getLocalString("dlg.cancel_btn", "Cancel"));
095: cancelButton.addActionListener(new ActionListener() {
096: public void actionPerformed(ActionEvent evt) {
097: NewFilterFromBug.this .dispose();
098: }
099: });
100: Util.addOkAndCancelButtons(south, okButton, cancelButton);
101: add(south, BorderLayout.SOUTH);
102:
103: pack();
104: setVisible(true);
105: }
106:
107: static void closeAll() {
108: for (NewFilterFromBug frame : listOfAllFrames)
109: frame.dispose();
110: listOfAllFrames.clear();
111: }
112: }
|