| 1 19 20 package edu.umd.cs.findbugs.gui2; 21 22 import java.awt.BorderLayout ; 23 import java.awt.event.ActionEvent ; 24 import java.awt.event.ActionListener ; 25 import java.util.ArrayList ; 26 import java.util.HashMap ; 27 import java.util.List ; 28 29 import javax.swing.Box ; 30 import javax.swing.BoxLayout ; 31 import javax.swing.ButtonGroup ; 32 import javax.swing.JButton ; 33 import javax.swing.JFrame ; 34 import javax.swing.JLabel ; 35 import javax.swing.JPanel ; 36 import javax.swing.JRadioButton ; 37 import javax.swing.tree.TreeModel ; 38 39 import edu.umd.cs.findbugs.BugInstance; 40 41 44 @SuppressWarnings ("serial") 45 public class NewFilterFromBug extends FBDialog 46 { 47 private HashMap <JRadioButton , Sortables> map = new HashMap <JRadioButton , Sortables>(); 48 private JRadioButton selectedRadioButton = null; 49 static List <NewFilterFromBug> listOfAllFrames=new ArrayList <NewFilterFromBug>(); 50 51 public NewFilterFromBug(final BugInstance bug) 52 { 53 this.setModal(true); 54 listOfAllFrames.add(this); 55 setLayout(new BorderLayout ()); 56 add(new JLabel ("Filter out all bugs whose..."), BorderLayout.NORTH); 57 58 JPanel center = new JPanel (); 59 center.setLayout(new BoxLayout (center, BoxLayout.Y_AXIS)); 60 ButtonGroup group = new ButtonGroup (); 61 for (Sortables s : Sortables.values()) 62 { 63 if (s.equals(Sortables.DIVIDER)) 64 continue; 65 JRadioButton radio = new JRadioButton (s.toString() + " is " + s.formatValue(s.getFrom(bug))); 66 radio.addActionListener(new ActionListener () { 67 public void actionPerformed(ActionEvent evt) 68 { 69 selectedRadioButton = (JRadioButton ) 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 south = new JPanel (); 79 JButton okButton = new JButton ("OK"); 80 okButton.addActionListener(new ActionListener () 81 { 82 public void actionPerformed(ActionEvent evt) 83 { 84 if (selectedRadioButton != null) 85 { 86 FilterMatcher newFilter=new FilterMatcher(map.get(selectedRadioButton), map.get(selectedRadioButton).getFrom(bug)); 87 ArrayList <FilterMatcher> filters=ProjectSettings.getInstance().getAllFilters(); 88 if (!filters.contains(newFilter)) 89 { 90 ProjectSettings.getInstance().addFilter(newFilter); 91 } 92 else { 94 filters.get(filters.indexOf(newFilter)).setActive(true); 95 } 96 PreferencesFrame.getInstance().updateFilterPanel(); 97 NewFilterFromBug.this.dispose(); 98 } 99 } 100 }); 101 JButton cancelButton = new JButton ("Cancel"); 102 cancelButton.addActionListener(new ActionListener () 103 { 104 public void actionPerformed(ActionEvent evt) 105 { 106 NewFilterFromBug.this.dispose(); 107 } 108 }); 109 south.setLayout(new BoxLayout (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 |