1 package net.sf.bse.gui;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28 import java.awt.event.MouseAdapter;
29 import java.awt.event.MouseEvent;
30 import java.awt.event.MouseListener;
31 import java.io.File;
32
33 import javax.swing.JMenuItem;
34 import javax.swing.JPopupMenu;
35 import javax.swing.JTree;
36 import javax.swing.event.TreeModelEvent;
37 import javax.swing.event.TreeModelListener;
38
39 /***
40 * @author Aleksi Peebles (aleksi.peebles@infocast.fi)
41 * @version $Revision: 1.1 $ $Date: 2003/01/17 14:40:27 $
42 */
43 public class XletTree extends JTree implements ActionListener, TreeModelListener
44 {
45 private JPopupMenu popup;
46
47 public XletTree()
48 {
49 this(new File(System.getProperty("user.dir")));
50 }
51
52 public XletTree(File root)
53 {
54 super(new XletTreeModel(root));
55 setCellRenderer(new XletTreeCellRenderer());
56 getModel().addTreeModelListener(this);
57
58 popup = new JPopupMenu();
59 JMenuItem item = new JMenuItem("Set Signed");
60 item.addActionListener(this);
61 popup.add(item);
62 item = new JMenuItem("Set Unsigned");
63 item.addActionListener(this);
64 popup.add(item);
65
66 MouseListener popupListener = new PopupListener();
67 addMouseListener(popupListener);
68 }
69
70 public void setRoot(File root)
71 {
72 ((XletTreeModel)getModel()).setRoot(root);
73 }
74
75 public File getRoot()
76 {
77 return (File)((XletTreeModel)getModel()).getRoot();
78 }
79
80 public void setRecursiveSelection(boolean recursive)
81 {
82 ((XletTreeModel)getModel()).setRecursiveSelection(recursive);
83 }
84
85 public boolean isRecursiveSelection()
86 {
87 return ((XletTreeModel)getModel()).isRecursiveSelection();
88 }
89
90 public String[] getSignFileNames()
91 {
92 return ((XletTreeModel)getModel()).getSignFileNames();
93 }
94
95
96
97
98
99 /***
100 * Invoked when a popup menu item is selected.
101 */
102 public void actionPerformed(ActionEvent e)
103 {
104 XletTreeModel model = (XletTreeModel)getModel();
105 if (e.getActionCommand().equals("Set Signed"))
106 {
107
108 model.setSigned(getSelectionModel(), "MD5");
109 }
110 else
111 {
112 model.setUnsigned(getSelectionModel());
113 }
114 }
115
116
117
118
119
120 public void treeNodesChanged(TreeModelEvent e)
121 {
122 repaint();
123 }
124
125 public void treeNodesInserted(TreeModelEvent e)
126 {
127 }
128
129 public void treeNodesRemoved(TreeModelEvent e)
130 {
131 }
132
133 public void treeStructureChanged(TreeModelEvent e)
134 {
135 }
136
137 /***
138 * Popup menu listener class
139 */
140 private class PopupListener extends MouseAdapter
141 {
142 public void mousePressed(MouseEvent e)
143 {
144 maybeShowPopup(e);
145 }
146
147 public void mouseReleased(MouseEvent e)
148 {
149 maybeShowPopup(e);
150 }
151
152 private void maybeShowPopup(MouseEvent e)
153 {
154 if (getSelectionCount() > 0 && e.isPopupTrigger())
155 {
156 popup.show(e.getComponent(), e.getX(), e.getY());
157 }
158 }
159 }
160 }