1 19 20 package org.netbeans.modules.java.navigation.actions; 21 22 import java.awt.event.ActionEvent ; 23 import javax.swing.AbstractAction ; 24 import javax.swing.Action ; 25 import javax.swing.JMenuItem ; 26 import javax.swing.JRadioButtonMenuItem ; 27 import org.netbeans.modules.java.navigation.ClassMemberFilters; 28 import org.openide.util.NbBundle; 29 import org.openide.util.actions.Presenter; 30 31 35 public abstract class SortActionSupport extends AbstractAction implements Presenter.Popup { 36 37 private JRadioButtonMenuItem menuItem; 38 protected ClassMemberFilters filters; 39 40 41 public SortActionSupport ( ClassMemberFilters filters ) { 42 this.filters = filters; 43 } 44 45 public final JMenuItem getPopupPresenter() { 46 JMenuItem result = obtainMenuItem(); 47 updateMenuItem(); 48 return result; 49 } 50 51 protected final JRadioButtonMenuItem obtainMenuItem () { 52 if (menuItem == null) { 53 menuItem = new JRadioButtonMenuItem ((String )getValue(Action.NAME)); 54 menuItem.setAction(this); 55 } 56 return menuItem; 57 } 58 59 protected abstract void updateMenuItem (); 60 61 62 64 public static final class SortByNameAction extends SortActionSupport { 65 66 public SortByNameAction ( ClassMemberFilters filters) { 67 super(filters); 68 putValue(Action.NAME, NbBundle.getMessage(SortByNameAction.class, "LBL_SortByName")); } 70 71 public void actionPerformed (ActionEvent e) { 72 filters.setNaturalSort(false); 73 updateMenuItem(); 74 } 75 76 protected void updateMenuItem () { 77 JRadioButtonMenuItem mi = obtainMenuItem(); 78 mi.setSelected(!filters.isNaturalSort()); 79 } 80 } 82 84 public static final class SortBySourceAction extends SortActionSupport { 85 86 public SortBySourceAction ( ClassMemberFilters filters ) { 87 super(filters); 88 putValue(Action.NAME, NbBundle.getMessage(SortBySourceAction.class, "LBL_SortBySource")); } 90 91 public void actionPerformed (ActionEvent e) { 92 filters.setNaturalSort(true); 93 updateMenuItem(); 94 } 95 96 protected void updateMenuItem () { 97 JRadioButtonMenuItem mi = obtainMenuItem(); 98 mi.setSelected(filters.isNaturalSort()); 99 } 100 } 102 103 } 104 | Popular Tags |