Coverage Report - wjhk.jupload2.gui.JUploadDebugPopupMenu
 
Classes in this File Line Coverage Branch Coverage Complexity
JUploadDebugPopupMenu
53 %
33/62
4 %
1/24
2,833
 
 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.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  
  * Global applet popup menu. It currently contains only the debug on/off menu entry.
 44  
  */
 45  
 
 46  
 final class JUploadDebugPopupMenu extends JPopupMenu implements ActionListener, ItemListener, PopupMenuListener {
 47  
 
 48  
     /** A generated serialVersionUID, to avoid warning during compilation */
 49  
     private static final long serialVersionUID = -5473337111643079720L;
 50  
 
 51  
     /**
 52  
      * Identifies the menu item that will set debug mode on or off (on means: debugLevel=100)
 53  
      */
 54  33
     JCheckBoxMenuItem cbmiDebugOnOff = null;
 55  
 
 56  33
     JCheckBoxMenuItem cbmiLogWindowOnOff = null;
 57  
 
 58  33
     JCheckBoxMenuItem cbmiTreeViewOnOff = null;
 59  
 
 60  33
     JMenuItem jMenuItemViewLastResponseBody = null;
 61  
 
 62  33
     JMenuItem jMenuItemClearLogWindowContent = null;
 63  
 
 64  33
     JMenuItem jMenuItemCopyLogWindowContent = null;
 65  
 
 66  
     /**
 67  
      * The current upload policy.
 68  
      */
 69  
     private UploadPolicy uploadPolicy;
 70  
 
 71  33
     JUploadDebugPopupMenu(UploadPolicy uploadPolicy) {
 72  33
         this.uploadPolicy = uploadPolicy;
 73  
 
 74  33
         this.addPopupMenuListener(this);
 75  
 
 76  
         // ////////////////////////////////////////////////////////////////////////
 77  
         // Creation of the menu items
 78  
         // ////////////////////////////////////////////////////////////////////////
 79  
         // First: debug on or off
 80  33
         this.cbmiDebugOnOff = new JCheckBoxMenuItem("Debug enabled");
 81  33
         this.cbmiDebugOnOff.setState(this.uploadPolicy.getDebugLevel() == 100);
 82  33
         add(this.cbmiDebugOnOff);
 83  33
         this.cbmiDebugOnOff.addItemListener(this);
 84  
         // Show or hide the log window
 85  33
         this.cbmiLogWindowOnOff = new JCheckBoxMenuItem("Show log window");
 86  33
         this.cbmiLogWindowOnOff.setState(this.uploadPolicy.getShowLogWindow().equals("true"));
 87  33
         add(this.cbmiLogWindowOnOff);
 88  33
         this.cbmiLogWindowOnOff.addItemListener(this);
 89  
         // Show the flat or the tree view
 90  33
         this.cbmiTreeViewOnOff = new JCheckBoxMenuItem("Show the file list in Tree View mode");
 91  33
         this.cbmiTreeViewOnOff.setState(this.uploadPolicy.getFileListViewMode().equals(FileListViewMode.TREE_VIEW));
 92  33
         add(this.cbmiTreeViewOnOff);
 93  33
         this.cbmiTreeViewOnOff.addItemListener(this);
 94  
 
 95  33
         add(new JSeparator());
 96  
 
 97  
         // Clear the last stringResponseBody
 98  33
         this.jMenuItemClearLogWindowContent = new JMenuItem("Clear the log window content");
 99  33
         add(this.jMenuItemClearLogWindowContent);
 100  33
         this.jMenuItemClearLogWindowContent.addActionListener(this);
 101  
         // Copy the last stringResponseBody
 102  33
         this.jMenuItemCopyLogWindowContent = new JMenuItem("Copy the log window content");
 103  33
         add(this.jMenuItemCopyLogWindowContent);
 104  33
         this.jMenuItemCopyLogWindowContent.addActionListener(this);
 105  
 
 106  33
         add(new JSeparator());
 107  
 
 108  
         // View the last stringResponseBody
 109  33
         this.jMenuItemViewLastResponseBody = new JMenuItem("View last response body");
 110  33
         add(this.jMenuItemViewLastResponseBody);
 111  33
         this.jMenuItemViewLastResponseBody.addActionListener(this);
 112  
         // ////////////////////////////////////////////////////////////////////////
 113  33
     }
 114  
 
 115  
     /**
 116  
      * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
 117  
      */
 118  
     public void itemStateChanged(ItemEvent e) {
 119  0
         if (this.cbmiDebugOnOff == e.getItem()) {
 120  0
             this.uploadPolicy.setDebugLevel((this.cbmiDebugOnOff.isSelected() ? 100 : 0));
 121  0
         } else if (this.cbmiLogWindowOnOff == e.getItem()) {
 122  0
             if (this.cbmiLogWindowOnOff.isSelected()) {
 123  0
                 this.uploadPolicy.setShowLogWindow(UploadPolicy.SHOWLOGWINDOW_TRUE);
 124  
             } else {
 125  0
                 this.uploadPolicy.setShowLogWindow(UploadPolicy.SHOWLOGWINDOW_FALSE);
 126  
             }
 127  0
         } else if (this.cbmiTreeViewOnOff == e.getItem()) {
 128  0
             if (this.cbmiTreeViewOnOff.isSelected()) {
 129  0
                 this.uploadPolicy.getContext().getUploadPanel().getFilePanel()
 130  0
                         .setFileListViewMode(FilePanel.FileListViewMode.TREE_VIEW);
 131  
             } else {
 132  0
                 this.uploadPolicy.getContext().getUploadPanel().getFilePanel()
 133  0
                         .setFileListViewMode(FilePanel.FileListViewMode.FLAT);
 134  
             }
 135  0
             ((JComponent) (this.uploadPolicy.getContext().getUploadPanel().getFilePanel())).validate();
 136  
         }
 137  0
     }
 138  
 
 139  
     /**
 140  
      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
 141  
      */
 142  
     public void actionPerformed(ActionEvent e) {
 143  0
         if (this.jMenuItemViewLastResponseBody == e.getSource()) {
 144  
             try {
 145  0
                 new DebugDialog(null, this.uploadPolicy.getLastResponseBody(), this.uploadPolicy);
 146  0
             } catch (JUploadIOException e1) {
 147  0
                 this.uploadPolicy.displayErr(e1);
 148  0
             }
 149  0
         } else if (this.jMenuItemClearLogWindowContent == e.getSource()) {
 150  0
             this.uploadPolicy.getContext().getUploadPanel().clearLogWindow();
 151  0
         } else if (this.jMenuItemCopyLogWindowContent == e.getSource()) {
 152  0
             this.uploadPolicy.getContext().getUploadPanel().copyLogWindow();
 153  
         }
 154  0
     }
 155  
 
 156  
     /** @see javax.swing.event.PopupMenuListener#popupMenuCanceled(javax.swing.event.PopupMenuEvent) */
 157  
     public void popupMenuCanceled(PopupMenuEvent arg0) {
 158  
         // Nothing to do.
 159  0
     }
 160  
 
 161  
     /** @see javax.swing.event.PopupMenuListener#popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent) */
 162  
     public void popupMenuWillBecomeInvisible(PopupMenuEvent arg0) {
 163  
         // Nothing to do.
 164  0
     }
 165  
 
 166  
     /**
 167  
      * Set the "View last response body" menu enabled or disabled.
 168  
      * 
 169  
      * @see javax.swing.event.PopupMenuListener#popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent)
 170  
      */
 171  
     public void popupMenuWillBecomeVisible(PopupMenuEvent arg0) {
 172  0
         String s = this.uploadPolicy.getLastResponseBody();
 173  0
         this.jMenuItemViewLastResponseBody.setEnabled(s != null && !s.equals(""));
 174  0
     }
 175  
 }