1
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
27
28
29 package uk.ac.rdg.resc.jstyx.client.browser;
30
31 import org.apache.log4j.Logger;
32
33 import javax.swing.JPopupMenu;
34 import javax.swing.JMenuItem;
35 import java.awt.event.ActionListener;
36 import java.awt.event.ActionEvent;
37 import java.awt.Component;
38
39 import java.io.IOException;
40
41 import uk.ac.rdg.resc.jstyx.client.CStyxFile;
42 import uk.ac.rdg.resc.jstyx.client.CStyxFileInputStream;
43 import uk.ac.rdg.resc.jstyx.StyxException;
44 import uk.ac.rdg.resc.jstyx.StyxUtils;
45
46 /***
47 * Pop-up menu that is displayed when a user requests a pop-up on one of the
48 * files in the hierarchy. Doesn't work very well yet!
49 *
50 * @author Jon Blower
51 * $Revision: 377 $
52 * $Date: 2005-08-31 18:03:19 +0100 (Wed, 31 Aug 2005) $
53 * $Log$
54 * Revision 1.6 2005/08/31 17:03:18 jonblower
55 * Renamed "StyxFile*putStream*" to "CStyxFile*putStream*" for consistency with CStyxFile class
56 *
57 * Revision 1.5 2005/03/11 13:58:54 jonblower
58 * Merged MINA-Test_20059309 into main line of development
59 *
60 * Revision 1.4.2.1 2005/03/11 08:29:52 jonblower
61 * Moved to log4j logging system (from apache commons logging)
62 *
63 * Revision 1.4 2005/02/28 11:43:38 jonblower
64 * Tidied up logging code
65 *
66 * Revision 1.3 2005/02/18 17:52:40 jonblower
67 * Added client.browser package
68 *
69 */
70 public class StyxBrowserPopupMenu extends JPopupMenu
71 {
72
73 private static final Logger log = Logger.getLogger(StyxBrowserPopupMenu.class);
74
75 private JMenuItem openItem;
76 private JMenuItem writeItem;
77 private JMenuItem refreshItem;
78 private JMenuItem propertiesItem;
79
80 private FileNode node;
81
82 /*** Creates a new instance of StyxBrowserPopUpMenu */
83 public StyxBrowserPopupMenu()
84 {
85 openItem = new JMenuItem("Open");
86 writeItem = new JMenuItem("Write");
87 refreshItem = new JMenuItem("Refresh");
88 propertiesItem = new JMenuItem("Properties");
89 this.add(openItem);
90 this.add(writeItem);
91 this.add(refreshItem);
92 this.add(propertiesItem);
93 refreshItem.addActionListener(new ActionListener()
94 {
95 public void actionPerformed(ActionEvent e)
96 {
97 if (node != null)
98 {
99 node.refresh();
100 }
101 }
102 });
103 openItem.addActionListener(new OpenFileListener());
104 this.node = null;
105 }
106
107 /***
108 * Shows the context menu for the particular CStyxFile that is passed in
109 */
110 public void showContext(FileNode node, Component invoker, int x, int y)
111 {
112 this.node = node;
113 CStyxFile file = node.getFile();
114 try
115 {
116 if (file.isDirectory())
117 {
118 openItem.setVisible(false);
119 writeItem.setVisible(false);
120 }
121 else
122 {
123 openItem.setVisible(true);
124 writeItem.setVisible(true);
125 }
126 }
127 catch (StyxException se)
128 {
129
130 se.printStackTrace();
131 }
132 super.show(invoker, x, y);
133 }
134
135 class OpenFileListener implements ActionListener
136 {
137 public void actionPerformed(ActionEvent e)
138 {
139
140 if (node != null)
141 {
142 CStyxFile file = node.getFile();
143 CStyxFileInputStream is = new CStyxFileInputStream(file);
144 TextDisplayer display = new TextDisplayer(file.getName());
145 display.setVisible(true);
146 try
147 {
148 display.displayData(is);
149 }
150 catch(IOException ioe)
151 {
152 ioe.printStackTrace();
153 }
154 }
155 else
156 {
157 log.error("node is null");
158 }
159 }
160 }
161
162 }