KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > monitor > client > SortButton


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 /**
21  * @author Ana von Klopp
22  */

23
24 package org.netbeans.modules.web.monitor.client;
25
26 import java.awt.event.ActionEvent JavaDoc;
27 import java.awt.event.ActionListener JavaDoc;
28 import java.util.logging.Logger JavaDoc;
29 import javax.swing.Icon JavaDoc;
30 import javax.swing.ImageIcon JavaDoc;
31 import javax.swing.JButton JavaDoc;
32
33 import org.openide.util.NbBundle;
34
35
36 class SortButton extends JButton JavaDoc {
37
38     private int state = DisplayTable.NEUTRAL;
39
40     private Icon JavaDoc[] icon = new Icon JavaDoc[3];
41     
42     public SortButton(final DisplayTable dt) {
43     super();
44     icon[0] = new ImageIcon JavaDoc(TransactionView.class.getResource
45                 ("/org/netbeans/modules/web/monitor/client/icons/unsorted.gif")); // NOI18N)
46
icon[1] = new ImageIcon JavaDoc(TransactionView.class.getResource
47                 ("/org/netbeans/modules/web/monitor/client/icons/a2z.gif")); // NOI18N
48
icon[2] = new ImageIcon JavaDoc(TransactionView.class.getResource
49                 ("/org/netbeans/modules/web/monitor/client/icons/z2a.gif")); // NOI18N
50
setIcon(icon[state]);
51     setBorder(null);
52     setBorderPainted(false);
53         setToolTipText(NbBundle.getBundle(TransactionView.class).getString("ACS_SortButtonUnsortedA11yDesc"));
54     
55     addActionListener(new ActionListener JavaDoc() {
56         public void actionPerformed(ActionEvent JavaDoc e) {
57     
58                     Logger.getLogger(SortButton.class.getName()).info("Sort requested");
59             
60             state++;
61             state=state%3;
62
63                     Logger.getLogger(SortButton.class.getName()).info("State is: " + String.valueOf(state));
64             JButton JavaDoc b = (JButton JavaDoc)e.getSource();
65             b.setIcon(icon[state]);
66             
67             if(state == DisplayTable.NEUTRAL)
68                     {
69             // PENDING
70
SortButton.this.setToolTipText(NbBundle.getBundle(TransactionView.class).getString("ACS_SortButtonUnsortedA11yDesc"));
71                     }
72             else if(state == DisplayTable.A2Z) {
73                         SortButton.this.setToolTipText(NbBundle.getBundle(TransactionView.class).getString("ACS_SortButtonSortAZA11yDesc"));
74             } else if(state == DisplayTable.Z2A) {
75                         SortButton.this.setToolTipText(NbBundle.getBundle(TransactionView.class).getString("ACS_SortButtonSortZAA11yDesc"));
76                     }
77             dt.setSorting(state);
78         }
79         });
80     }
81
82     int getMode() {
83     return state;
84     }
85 } // SortButton
86
Popular Tags