Coverage Report - wjhk.jupload2.policies.SuperSimpleUploadPolicy
 
Classes in this File Line Coverage Branch Coverage Complexity
SuperSimpleUploadPolicy
0 %
0/69
0 %
0/8
2
 
 1  
 //
 2  
 // $Id: DefaultUploadPolicy.java 289 2007-06-19 10:04:46 +0000 (mar., 19 juin
 3  
 // 2007) etienne_sf $
 4  
 //
 5  
 // jupload - A file upload juploadContext.
 6  
 // Copyright 2007 The JUpload Team
 7  
 //
 8  
 // Created: 2006-05-04
 9  
 // Creator: etienne_sf
 10  
 // Last modified: $Date: 2010-02-12 18:25:00 +0100 (ven, 12 Feb 2010) $
 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.policies;
 23  
 
 24  
 import java.awt.BorderLayout;
 25  
 import java.awt.Color;
 26  
 import java.awt.Component;
 27  
 import java.awt.GridLayout;
 28  
 import java.awt.SystemColor;
 29  
 import java.awt.dnd.DropTarget;
 30  
 
 31  
 import javax.swing.BorderFactory;
 32  
 import javax.swing.BoxLayout;
 33  
 import javax.swing.JButton;
 34  
 import javax.swing.JLabel;
 35  
 import javax.swing.JPanel;
 36  
 import javax.swing.SwingConstants;
 37  
 
 38  
 import wjhk.jupload2.context.JUploadContext;
 39  
 import wjhk.jupload2.exception.JUploadException;
 40  
 import wjhk.jupload2.gui.JUploadPanel;
 41  
 
 42  
 /**
 43  
  * A SuperSimpleUploadPolicy - see
 44  
  * https://sourceforge.net/tracker/?func=detail&atid
 45  
  * =490055&aid=2954497&group_id=59144
 46  
  * 
 47  
  * @author nordfalk
 48  
  * @version $Revision: 978 $
 49  
  */
 50  
 
 51  
 public class SuperSimpleUploadPolicy extends DefaultUploadPolicy {
 52  
 
 53  
         /**
 54  
          * The main constructor : use default values, and the given postURL.
 55  
          * 
 56  
          * @param juploadContext
 57  
          *            The current juploadContext. As the reference to the current
 58  
          *            upload policy exists almost everywhere, this parameter allows
 59  
          *            any access to anyone on the juploadContext... including
 60  
          *            reading the applet parameters.
 61  
          * @throws JUploadException
 62  
          *             If an applet parameter is invalid
 63  
          */
 64  
         public SuperSimpleUploadPolicy(JUploadContext juploadContext)
 65  
                         throws JUploadException {
 66  0
                 super(juploadContext);
 67  0
         }
 68  
 
 69  
         /**
 70  
          * Implementation of
 71  
          * {@link wjhk.jupload2.policies.UploadPolicy#createTopPanel(JButton, JButton, JButton, JUploadPanel)}
 72  
          * 
 73  
          * @see wjhk.jupload2.policies.UploadPolicy#createTopPanel(JButton, JButton,
 74  
          *      JButton, JUploadPanel)
 75  
          */
 76  
         public JPanel createTopPanel(JButton browse, JButton remove,
 77  
                         JButton removeAll, JUploadPanel jUploadPanel) {
 78  0
                 JPanel jPanel = new JPanel();
 79  
 
 80  0
                 jPanel.setLayout(new GridLayout(1, 3, 10, 5));
 81  0
                 jPanel.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
 82  0
                 jPanel.add(browse);
 83  
                 // jPanel.add(removeAll);
 84  0
                 jPanel.add(remove);
 85  0
                 remove.setVisible(false); // will appear after first file has been added
 86  
 
 87  0
                 jUploadPanel.getJComponent().setBorder(
 88  0
                                 BorderFactory.createLineBorder(SystemColor.controlDkShadow));
 89  
 
 90  0
                 jPanel.setBackground(Color.WHITE);
 91  
 
 92  0
                 return jPanel;
 93  
         }
 94  
 
 95  
         JPanel dndFilesHere;
 96  
         JPanel progressPanel;
 97  
         JPanel statusBar;
 98  
 
 99  
         /**
 100  
          * This methods allow the upload policy to override the default disposition
 101  
          * of the components on the applet.
 102  
          * 
 103  
          * @see UploadPolicy#addComponentsToJUploadPanel(JUploadPanel)
 104  
          */
 105  
         public void addComponentsToJUploadPanel(JUploadPanel jUploadPanel) {
 106  
                 // Set the global layout of the panel.
 107  0
                 jUploadPanel.getJComponent().setLayout(
 108  0
                                 new BoxLayout(jUploadPanel.getJComponent(), BoxLayout.Y_AXIS));
 109  
 
 110  
                 // The top panel is the upper part of the applet: above the file
 111  
                 // list.
 112  
                 // JPanel topPanel = new JPanel();
 113  0
                 JPanel topPanel = createTopPanel(jUploadPanel.getBrowseButton(),
 114  0
                                 jUploadPanel.getRemoveButton(), jUploadPanel
 115  0
                                                 .getRemoveAllButton(), jUploadPanel);
 116  0
                 if (topPanel != null) {
 117  0
                         jUploadPanel.getJComponent().add(topPanel);
 118  0
                         topPanel.addMouseListener(jUploadPanel.getMouseListener());
 119  
                 }
 120  
 
 121  0
                 Component c = jUploadPanel.getFilePanel().getDropComponent();
 122  
                 // Then, we add the file list.
 123  0
                 jUploadPanel.getJComponent().add(c);
 124  0
                 c.setVisible(false);
 125  
 
 126  0
                 c.setBackground(Color.WHITE);
 127  
 
 128  0
                 dndFilesHere = new JPanel();
 129  0
                 new DropTarget(this.dndFilesHere, jUploadPanel.getDndListener());
 130  
 
 131  0
                 dndFilesHere.setLayout(new BorderLayout());
 132  0
                 dndFilesHere.setBackground(Color.WHITE);
 133  0
                 JLabel jlabel = new JLabel(
 134  0
                                 getLocalizedString("dragDirectoriesAndFilesToHere"));
 135  0
                 jlabel.setFont(jlabel.getFont().deriveFont(36f));
 136  0
                 jlabel.setHorizontalAlignment(SwingConstants.CENTER);
 137  0
                 dndFilesHere.add(jlabel, BorderLayout.CENTER);
 138  0
                 jUploadPanel.getJComponent().add(dndFilesHere);
 139  
 
 140  
                 // The progress panel contains the progress bar, and the upload and stop
 141  
                 // buttons.
 142  0
                 progressPanel = createProgressPanel(jUploadPanel
 143  0
                                 .getPreparationProgressBar(), jUploadPanel
 144  0
                                 .getUploadProgressBar(), jUploadPanel.getUploadButton(),
 145  0
                                 jUploadPanel.getStopButton(), jUploadPanel);
 146  0
                 jUploadPanel.getJComponent().add(progressPanel);
 147  0
                 jUploadPanel.getJComponent().addMouseListener(
 148  0
                                 jUploadPanel.getMouseListener());
 149  
 
 150  0
                 progressPanel.setVisible(false); // will appear after 1st file drop
 151  0
                 progressPanel.setBackground(Color.WHITE);
 152  
 
 153  
                 // Now, we add the log window.
 154  0
                 jUploadPanel.showOrHideLogWindow();
 155  0
                 jUploadPanel.getJComponent().add(jUploadPanel.getJLogWindowPane());
 156  
 
 157  
                 // And, to finish with: the status bar.
 158  0
                 statusBar = createStatusBar(jUploadPanel.getStatusLabel(), jUploadPanel);
 159  0
                 if (null != statusBar) {
 160  0
                         jUploadPanel.getJComponent().add(statusBar);
 161  0
                         statusBar.addMouseListener(jUploadPanel.getMouseListener());
 162  
 
 163  0
                         statusBar.setVisible(false);
 164  0
                         statusBar.setBackground(Color.WHITE);
 165  0
                         jUploadPanel.getStatusLabel().setText(" ");
 166  
                 }
 167  0
         }
 168  
 
 169  
         /** {@inheritDoc} */
 170  
         public void updateButtonState(int executionStatus) {
 171  0
                 super.updateButtonState(executionStatus);
 172  0
                 if (executionStatus == UploadPolicy.EXEC_STATUS_READY) {
 173  0
                         this.juploadContext.getUploadPanel().getRemoveButton().setVisible(
 174  
                                         true);
 175  0
                         this.dndFilesHere.setVisible(false);
 176  0
                         this.progressPanel.setVisible(true);
 177  0
                         this.statusBar.setVisible(true);
 178  0
                         this.juploadContext.getUploadPanel().getFilePanel()
 179  0
                                         .getDropComponent().setVisible(true);
 180  0
                 } else if (executionStatus == UploadPolicy.EXEC_STATUS_UPLOADING) {
 181  0
                         this.juploadContext.getUploadPanel().getRemoveButton().setVisible(
 182  
                                         true);
 183  0
                         this.dndFilesHere.setVisible(false);
 184  0
                         this.progressPanel.setVisible(true);
 185  0
                         this.statusBar.setVisible(true);
 186  0
                         this.juploadContext.getUploadPanel().getFilePanel()
 187  0
                                         .getDropComponent().setVisible(true);
 188  
                 }
 189  
 
 190  0
         }
 191  
 
 192  
 }