1 | //
|
---|
2 | // $Id: JUploadPanelImpl.java 303 2007-07-21 07:42:51 +0000 (sam., 21 juil. 2007)
|
---|
3 | // etienne_sf $
|
---|
4 | //
|
---|
5 | // jupload - A file upload applet.
|
---|
6 | // Copyright 2007 The JUpload Team
|
---|
7 | //
|
---|
8 | // Created: ?
|
---|
9 | // Creator: etienne_sf
|
---|
10 | // Last modified: $Date: 2007-10-08 10:02:41 +0200 (lun., 08 oct. 2007) $
|
---|
11 | //
|
---|
12 | // This program is free software; you can redistribute it and/or modify it under
|
---|
13 | // the terms of the GNU General Public License as published by the Free Software
|
---|
14 | // Foundation; either version 2 of the License, or (at your option) any later
|
---|
15 | // version. This program is distributed in the hope that it will be useful, but
|
---|
16 | // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
---|
17 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
---|
18 | // details. You should have received a copy of the GNU General Public License
|
---|
19 | // along with this program; if not, write to the Free Software Foundation, Inc.,
|
---|
20 | // 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
21 |
|
---|
22 | package wjhk.jupload2.gui;
|
---|
23 |
|
---|
24 | import java.awt.event.ActionEvent;
|
---|
25 | import java.awt.event.ActionListener;
|
---|
26 | import java.awt.event.ItemEvent;
|
---|
27 | import java.awt.event.ItemListener;
|
---|
28 |
|
---|
29 | import javax.swing.JCheckBoxMenuItem;
|
---|
30 | import javax.swing.JMenuItem;
|
---|
31 | import javax.swing.JPopupMenu;
|
---|
32 | import javax.swing.event.PopupMenuEvent;
|
---|
33 | import javax.swing.event.PopupMenuListener;
|
---|
34 |
|
---|
35 | import wjhk.jupload2.exception.JUploadIOException;
|
---|
36 | import wjhk.jupload2.policies.UploadPolicy;
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * Global applet popup menu. It currently contains only the debug on/off menu
|
---|
40 | * entry.
|
---|
41 | */
|
---|
42 |
|
---|
43 | final class JUploadDebugPopupMenu extends JPopupMenu implements ActionListener,
|
---|
44 | ItemListener, PopupMenuListener {
|
---|
45 |
|
---|
46 | /** A generated serialVersionUID, to avoid warning during compilation */
|
---|
47 | private static final long serialVersionUID = -5473337111643079720L;
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Identifies the menu item that will set debug mode on or off (on means:
|
---|
51 | * debugLevel=100)
|
---|
52 | */
|
---|
53 | JCheckBoxMenuItem cbmiDebugOnOff = null;
|
---|
54 |
|
---|
55 | JCheckBoxMenuItem cbmiLogWindowOnOff = null;
|
---|
56 |
|
---|
57 | JMenuItem jMenuItemViewLastResponseBody = null;
|
---|
58 |
|
---|
59 | JMenuItem jMenuItemClearLogWindowContent = null;
|
---|
60 |
|
---|
61 | JMenuItem jMenuItemCopyLogWindowContent = null;
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * The current upload policy.
|
---|
65 | */
|
---|
66 | private UploadPolicy uploadPolicy;
|
---|
67 |
|
---|
68 | JUploadDebugPopupMenu(UploadPolicy uploadPolicy) {
|
---|
69 | this.uploadPolicy = uploadPolicy;
|
---|
70 |
|
---|
71 | this.addPopupMenuListener(this);
|
---|
72 |
|
---|
73 | // ////////////////////////////////////////////////////////////////////////
|
---|
74 | // Creation of the menu items
|
---|
75 | // ////////////////////////////////////////////////////////////////////////
|
---|
76 | // First: debug on or off
|
---|
77 | this.cbmiDebugOnOff = new JCheckBoxMenuItem("Debug enabled");
|
---|
78 | this.cbmiDebugOnOff.setState(this.uploadPolicy.getDebugLevel() == 100);
|
---|
79 | add(this.cbmiDebugOnOff);
|
---|
80 | this.cbmiDebugOnOff.addItemListener(this);
|
---|
81 | // Show or hide the log window
|
---|
82 | this.cbmiLogWindowOnOff = new JCheckBoxMenuItem("Show log window");
|
---|
83 | this.cbmiLogWindowOnOff.setState(this.uploadPolicy.getShowLogWindow()
|
---|
84 | .equals("true"));
|
---|
85 | add(this.cbmiLogWindowOnOff);
|
---|
86 | this.cbmiLogWindowOnOff.addItemListener(this);
|
---|
87 | // Clear the last stringResponseBody
|
---|
88 | this.jMenuItemClearLogWindowContent = new JMenuItem(
|
---|
89 | "Clear the log window content");
|
---|
90 | add(this.jMenuItemClearLogWindowContent);
|
---|
91 | this.jMenuItemClearLogWindowContent.addActionListener(this);
|
---|
92 | // Copy the last stringResponseBody
|
---|
93 | this.jMenuItemCopyLogWindowContent = new JMenuItem(
|
---|
94 | "Copy the log window content");
|
---|
95 | add(this.jMenuItemCopyLogWindowContent);
|
---|
96 | this.jMenuItemCopyLogWindowContent.addActionListener(this);
|
---|
97 | // View the last stringResponseBody
|
---|
98 | this.jMenuItemViewLastResponseBody = new JMenuItem(
|
---|
99 | "View last response body");
|
---|
100 | add(this.jMenuItemViewLastResponseBody);
|
---|
101 | this.jMenuItemViewLastResponseBody.addActionListener(this);
|
---|
102 | // ////////////////////////////////////////////////////////////////////////
|
---|
103 | }
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
|
---|
107 | */
|
---|
108 | public void itemStateChanged(ItemEvent e) {
|
---|
109 | if (this.cbmiDebugOnOff == e.getItem()) {
|
---|
110 | this.uploadPolicy
|
---|
111 | .setDebugLevel((this.cbmiDebugOnOff.isSelected() ? 100 : 0));
|
---|
112 | } else if (this.cbmiLogWindowOnOff == e.getItem()) {
|
---|
113 | if (this.cbmiLogWindowOnOff.isSelected()) {
|
---|
114 | this.uploadPolicy
|
---|
115 | .setShowLogWindow(UploadPolicy.SHOWLOGWINDOW_TRUE);
|
---|
116 | } else {
|
---|
117 | this.uploadPolicy
|
---|
118 | .setShowLogWindow(UploadPolicy.SHOWLOGWINDOW_FALSE);
|
---|
119 | }
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 | /**
|
---|
124 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
---|
125 | */
|
---|
126 | public void actionPerformed(ActionEvent e) {
|
---|
127 | if (this.jMenuItemViewLastResponseBody == e.getSource()) {
|
---|
128 | try {
|
---|
129 | new DebugDialog(null, this.uploadPolicy.getLastResponseBody(),
|
---|
130 | this.uploadPolicy);
|
---|
131 | } catch (JUploadIOException e1) {
|
---|
132 | this.uploadPolicy.displayErr(e1);
|
---|
133 | }
|
---|
134 | } else if (this.jMenuItemClearLogWindowContent == e.getSource()) {
|
---|
135 | this.uploadPolicy.getContext().getUploadPanel().clearLogWindow();
|
---|
136 | } else if (this.jMenuItemCopyLogWindowContent == e.getSource()) {
|
---|
137 | this.uploadPolicy.getContext().getUploadPanel().copyLogWindow();
|
---|
138 | }
|
---|
139 | }
|
---|
140 |
|
---|
141 | /** @see javax.swing.event.PopupMenuListener#popupMenuCanceled(javax.swing.event.PopupMenuEvent) */
|
---|
142 | public void popupMenuCanceled(PopupMenuEvent arg0) {
|
---|
143 | // Nothing to do.
|
---|
144 | }
|
---|
145 |
|
---|
146 | /** @see javax.swing.event.PopupMenuListener#popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent) */
|
---|
147 | public void popupMenuWillBecomeInvisible(PopupMenuEvent arg0) {
|
---|
148 | // Nothing to do.
|
---|
149 | }
|
---|
150 |
|
---|
151 | /**
|
---|
152 | * Set the "View last response body" menu enabled or disabled.
|
---|
153 | *
|
---|
154 | * @see javax.swing.event.PopupMenuListener#popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent)
|
---|
155 | */
|
---|
156 | public void popupMenuWillBecomeVisible(PopupMenuEvent arg0) {
|
---|
157 | String s = this.uploadPolicy.getLastResponseBody();
|
---|
158 | this.jMenuItemViewLastResponseBody.setEnabled(s != null
|
---|
159 | && !s.equals(""));
|
---|
160 | }
|
---|
161 | }
|
---|