KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > retouche > 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.retouche.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.retouche.navigation.ClassMemberFilters;
28 import org.openide.util.NbBundle;
29 import org.openide.util.actions.Presenter;
30
31 /**
32  * This file is originally from Retouche, the Java Support
33  * infrastructure in NetBeans. I have modified the file as little
34  * as possible to make merging Retouche fixes back as simple as
35  * possible.
36  * <p>
37  *
38  * "Radio button" type action, base class designed for subclassing
39  *
40  * @author Dafe Simonek
41  */

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

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")); //NOI18N
76
}
77     
78         public void actionPerformed (ActionEvent JavaDoc e) {
79             filters.setNaturalSort(false);
80             updateMenuItem();
81         }
82
83         protected void updateMenuItem () {
84             JRadioButtonMenuItem JavaDoc mi = obtainMenuItem();
85             mi.setSelected(!filters.isNaturalSort());
86         }
87     } // end of SortByNameAction
88

89     /** Enables sorting by names when selected
90      */

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")); //NOI18N
96
}
97     
98         public void actionPerformed (ActionEvent JavaDoc e) {
99             filters.setNaturalSort(true);
100             updateMenuItem();
101         }
102
103         protected void updateMenuItem () {
104             JRadioButtonMenuItem JavaDoc mi = obtainMenuItem();
105             mi.setSelected(filters.isNaturalSort());
106         }
107     } // end of SortBySourceAction
108

109     
110 }
111
Popular Tags