1 21 22 package org.armedbear.j; 23 24 import java.awt.event.ActionEvent ; 25 import java.awt.event.ActionListener ; 26 import javax.swing.JCheckBoxMenuItem ; 27 import javax.swing.JPopupMenu ; 28 29 public final class JavaTreePopupMenu extends JPopupMenu implements ActionListener 30 { 31 private static final String ARRANGE_BY_TYPE = "Arrange by type"; 32 private static final String SORT = "Sort alphabetically"; 33 34 private final JavaTree tree; 35 36 public JavaTreePopupMenu(JavaTree tree) 37 { 38 super(); 39 this.tree = tree; 40 JCheckBoxMenuItem item = new JCheckBoxMenuItem (ARRANGE_BY_TYPE); 41 item.setSelected(JavaTree.getArrangeByType()); 42 item.addActionListener(this); 43 add(item); 44 item = new JCheckBoxMenuItem (SORT); 45 item.setSelected(JavaTree.getSort()); 46 item.addActionListener(this); 47 add(item); 48 } 49 50 public void actionPerformed(ActionEvent e) 51 { 52 Object object = e.getSource(); 53 if (object instanceof JCheckBoxMenuItem ) { 54 JCheckBoxMenuItem item = (JCheckBoxMenuItem ) object; 55 boolean b = item.isSelected(); 56 String command = e.getActionCommand(); 57 if (command.equals(ARRANGE_BY_TYPE)) { 58 if (b != JavaTree.getArrangeByType()) { 59 JavaTree.setArrangeByType(b); 60 tree.refresh(true); 61 } 62 } else if (command.equals(SORT)) { 63 if (b != JavaTree.getSort()) { 64 JavaTree.setSort(b); 65 tree.refresh(true); 66 } 67 } 68 } 69 } 70 } 71 | Popular Tags |