KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > JavaTreePopupMenu


1 /*
2  * JavaTreePopupMenu.java
3  *
4  * Copyright (C) 2002 Peter Graves
5  * $Id: JavaTreePopupMenu.java,v 1.1.1.1 2002/09/24 16:08:05 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.j;
23
24 import java.awt.event.ActionEvent JavaDoc;
25 import java.awt.event.ActionListener JavaDoc;
26 import javax.swing.JCheckBoxMenuItem JavaDoc;
27 import javax.swing.JPopupMenu JavaDoc;
28
29 public final class JavaTreePopupMenu extends JPopupMenu JavaDoc implements ActionListener JavaDoc
30 {
31     private static final String JavaDoc ARRANGE_BY_TYPE = "Arrange by type";
32     private static final String JavaDoc SORT = "Sort alphabetically";
33
34     private final JavaTree tree;
35
36     public JavaTreePopupMenu(JavaTree tree)
37     {
38         super();
39         this.tree = tree;
40         JCheckBoxMenuItem JavaDoc item = new JCheckBoxMenuItem JavaDoc(ARRANGE_BY_TYPE);
41         item.setSelected(JavaTree.getArrangeByType());
42         item.addActionListener(this);
43         add(item);
44         item = new JCheckBoxMenuItem JavaDoc(SORT);
45         item.setSelected(JavaTree.getSort());
46         item.addActionListener(this);
47         add(item);
48     }
49
50     public void actionPerformed(ActionEvent JavaDoc e)
51     {
52         Object JavaDoc object = e.getSource();
53         if (object instanceof JCheckBoxMenuItem JavaDoc) {
54             JCheckBoxMenuItem JavaDoc item = (JCheckBoxMenuItem JavaDoc) object;
55             boolean b = item.isSelected();
56             String JavaDoc command = e.getActionCommand();
57             if (command.equals(ARRANGE_BY_TYPE)) {
58                 if (b != JavaTree.getArrangeByType()) {
59                     JavaTree.setArrangeByType(b);
60                     tree.refresh(true);
61                 }
62             } else if (command.equals(SORT)) {
63                 if (b != JavaTree.getSort()) {
64                     JavaTree.setSort(b);
65                     tree.refresh(true);
66                 }
67             }
68         }
69     }
70 }
71
Popular Tags