1 19 20 package org.netbeans.modules.retouche.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.retouche.navigation.ClassMemberFilters; 28 import org.openide.util.NbBundle; 29 import org.openide.util.actions.Presenter; 30 31 42 public abstract class SortActionSupport extends AbstractAction implements Presenter.Popup { 43 44 private JRadioButtonMenuItem menuItem; 45 protected ClassMemberFilters filters; 46 47 48 public SortActionSupport ( ClassMemberFilters filters ) { 49 this.filters = filters; 50 } 51 52 public final JMenuItem getPopupPresenter() { 53 JMenuItem result = obtainMenuItem(); 54 updateMenuItem(); 55 return result; 56 } 57 58 protected final JRadioButtonMenuItem obtainMenuItem () { 59 if (menuItem == null) { 60 menuItem = new JRadioButtonMenuItem ((String )getValue(Action.NAME)); 61 menuItem.setAction(this); 62 } 63 return menuItem; 64 } 65 66 protected abstract void updateMenuItem (); 67 68 69 71 public static final class SortByNameAction extends SortActionSupport { 72 73 public SortByNameAction ( ClassMemberFilters filters) { 74 super(filters); 75 putValue(Action.NAME, NbBundle.getMessage(SortByNameAction.class, "LBL_SortByName")); } 77 78 public void actionPerformed (ActionEvent e) { 79 filters.setNaturalSort(false); 80 updateMenuItem(); 81 } 82 83 protected void updateMenuItem () { 84 JRadioButtonMenuItem mi = obtainMenuItem(); 85 mi.setSelected(!filters.isNaturalSort()); 86 } 87 } 89 91 public static final class SortBySourceAction extends SortActionSupport { 92 93 public SortBySourceAction ( ClassMemberFilters filters ) { 94 super(filters); 95 putValue(Action.NAME, NbBundle.getMessage(SortBySourceAction.class, "LBL_SortBySource")); } 97 98 public void actionPerformed (ActionEvent e) { 99 filters.setNaturalSort(true); 100 updateMenuItem(); 101 } 102 103 protected void updateMenuItem () { 104 JRadioButtonMenuItem mi = obtainMenuItem(); 105 mi.setSelected(filters.isNaturalSort()); 106 } 107 } 109 110 } 111 | Popular Tags |