KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > navigation > actions > SortActionSupport


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.java.navigation.actions;
21
22 import java.awt.event.ActionEvent JavaDoc;
23 import javax.swing.AbstractAction JavaDoc;
24 import javax.swing.Action JavaDoc;
25 import javax.swing.JMenuItem JavaDoc;
26 import javax.swing.JRadioButtonMenuItem JavaDoc;
27 import org.netbeans.modules.java.navigation.ClassMemberFilters;
28 import org.openide.util.NbBundle;
29 import org.openide.util.actions.Presenter;
30
31 /** "Radio button" type action, base class designed for subclassing
32  *
33  * @author Dafe Simonek
34  */

35 public abstract class SortActionSupport extends AbstractAction JavaDoc implements Presenter.Popup {
36     
37     private JRadioButtonMenuItem JavaDoc menuItem;
38     protected ClassMemberFilters filters;
39     
40     /** Creates a new instance of SortByNameAction */
41     public SortActionSupport ( ClassMemberFilters filters ) {
42         this.filters = filters;
43     }
44     
45     public final JMenuItem JavaDoc getPopupPresenter() {
46         JMenuItem JavaDoc result = obtainMenuItem();
47         updateMenuItem();
48         return result;
49     }
50     
51     protected final JRadioButtonMenuItem JavaDoc obtainMenuItem () {
52         if (menuItem == null) {
53             menuItem = new JRadioButtonMenuItem JavaDoc((String JavaDoc)getValue(Action.NAME));
54             menuItem.setAction(this);
55         }
56         return menuItem;
57     }
58     
59     protected abstract void updateMenuItem ();
60     
61     
62     /** Enables sorting by names when selected
63      */

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")); //NOI18N
69
}
70     
71         public void actionPerformed (ActionEvent JavaDoc e) {
72             filters.setNaturalSort(false);
73             updateMenuItem();
74         }
75
76         protected void updateMenuItem () {
77             JRadioButtonMenuItem JavaDoc mi = obtainMenuItem();
78             mi.setSelected(!filters.isNaturalSort());
79         }
80     } // end of SortByNameAction
81

82     /** Enables sorting by names when selected
83      */

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")); //NOI18N
89
}
90     
91         public void actionPerformed (ActionEvent JavaDoc e) {
92             filters.setNaturalSort(true);
93             updateMenuItem();
94         }
95
96         protected void updateMenuItem () {
97             JRadioButtonMenuItem JavaDoc mi = obtainMenuItem();
98             mi.setSelected(filters.isNaturalSort());
99         }
100     } // end of SortBySourceAction
101

102     
103 }
104
Popular Tags