1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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.JComponent;
31 import javax.swing.JMenuItem;
32 import javax.swing.JPopupMenu;
33 import javax.swing.JSeparator;
34 import javax.swing.event.PopupMenuEvent;
35 import javax.swing.event.PopupMenuListener;
36
37 import wjhk.jupload2.exception.JUploadIOException;
38 import wjhk.jupload2.gui.filepanel.FilePanel;
39 import wjhk.jupload2.gui.filepanel.FilePanel.FileListViewMode;
40 import wjhk.jupload2.policies.UploadPolicy;
41
42
43
44
45
46 final class JUploadDebugPopupMenu extends JPopupMenu implements ActionListener, ItemListener, PopupMenuListener {
47
48
49 private static final long serialVersionUID = -5473337111643079720L;
50
51
52
53
54 JCheckBoxMenuItem cbmiDebugOnOff = null;
55
56 JCheckBoxMenuItem cbmiLogWindowOnOff = null;
57
58 JCheckBoxMenuItem cbmiTreeViewOnOff = null;
59
60 JMenuItem jMenuItemViewLastResponseBody = null;
61
62 JMenuItem jMenuItemClearLogWindowContent = null;
63
64 JMenuItem jMenuItemCopyLogWindowContent = null;
65
66
67
68
69 private UploadPolicy uploadPolicy;
70
71 JUploadDebugPopupMenu(UploadPolicy uploadPolicy) {
72 this.uploadPolicy = uploadPolicy;
73
74 this.addPopupMenuListener(this);
75
76
77
78
79
80 this.cbmiDebugOnOff = new JCheckBoxMenuItem("Debug enabled");
81 this.cbmiDebugOnOff.setState(this.uploadPolicy.getDebugLevel() == 100);
82 add(this.cbmiDebugOnOff);
83 this.cbmiDebugOnOff.addItemListener(this);
84
85 this.cbmiLogWindowOnOff = new JCheckBoxMenuItem("Show log window");
86 this.cbmiLogWindowOnOff.setState(this.uploadPolicy.getShowLogWindow().equals("true"));
87 add(this.cbmiLogWindowOnOff);
88 this.cbmiLogWindowOnOff.addItemListener(this);
89
90 this.cbmiTreeViewOnOff = new JCheckBoxMenuItem("Show the file list in Tree View mode");
91 this.cbmiTreeViewOnOff.setState(this.uploadPolicy.getFileListViewMode().equals(FileListViewMode.TREE_VIEW));
92 add(this.cbmiTreeViewOnOff);
93 this.cbmiTreeViewOnOff.addItemListener(this);
94
95 add(new JSeparator());
96
97
98 this.jMenuItemClearLogWindowContent = new JMenuItem("Clear the log window content");
99 add(this.jMenuItemClearLogWindowContent);
100 this.jMenuItemClearLogWindowContent.addActionListener(this);
101
102 this.jMenuItemCopyLogWindowContent = new JMenuItem("Copy the log window content");
103 add(this.jMenuItemCopyLogWindowContent);
104 this.jMenuItemCopyLogWindowContent.addActionListener(this);
105
106 add(new JSeparator());
107
108
109 this.jMenuItemViewLastResponseBody = new JMenuItem("View last response body");
110 add(this.jMenuItemViewLastResponseBody);
111 this.jMenuItemViewLastResponseBody.addActionListener(this);
112
113 }
114
115
116
117
118 public void itemStateChanged(ItemEvent e) {
119 if (this.cbmiDebugOnOff == e.getItem()) {
120 this.uploadPolicy.setDebugLevel((this.cbmiDebugOnOff.isSelected() ? 100 : 0));
121 } else if (this.cbmiLogWindowOnOff == e.getItem()) {
122 if (this.cbmiLogWindowOnOff.isSelected()) {
123 this.uploadPolicy.setShowLogWindow(UploadPolicy.SHOWLOGWINDOW_TRUE);
124 } else {
125 this.uploadPolicy.setShowLogWindow(UploadPolicy.SHOWLOGWINDOW_FALSE);
126 }
127 } else if (this.cbmiTreeViewOnOff == e.getItem()) {
128 if (this.cbmiTreeViewOnOff.isSelected()) {
129 this.uploadPolicy.getContext().getUploadPanel().getFilePanel()
130 .setFileListViewMode(FilePanel.FileListViewMode.TREE_VIEW);
131 } else {
132 this.uploadPolicy.getContext().getUploadPanel().getFilePanel()
133 .setFileListViewMode(FilePanel.FileListViewMode.FLAT);
134 }
135 ((JComponent) (this.uploadPolicy.getContext().getUploadPanel().getFilePanel())).validate();
136 }
137 }
138
139
140
141
142 public void actionPerformed(ActionEvent e) {
143 if (this.jMenuItemViewLastResponseBody == e.getSource()) {
144 try {
145 new DebugDialog(null, this.uploadPolicy.getLastResponseBody(), this.uploadPolicy);
146 } catch (JUploadIOException e1) {
147 this.uploadPolicy.displayErr(e1);
148 }
149 } else if (this.jMenuItemClearLogWindowContent == e.getSource()) {
150 this.uploadPolicy.getContext().getUploadPanel().clearLogWindow();
151 } else if (this.jMenuItemCopyLogWindowContent == e.getSource()) {
152 this.uploadPolicy.getContext().getUploadPanel().copyLogWindow();
153 }
154 }
155
156
157 public void popupMenuCanceled(PopupMenuEvent arg0) {
158
159 }
160
161
162 public void popupMenuWillBecomeInvisible(PopupMenuEvent arg0) {
163
164 }
165
166
167
168
169
170
171 public void popupMenuWillBecomeVisible(PopupMenuEvent arg0) {
172 String s = this.uploadPolicy.getLastResponseBody();
173 this.jMenuItemViewLastResponseBody.setEnabled(s != null && !s.equals(""));
174 }
175 }