[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/imagex/postlet/rev_unkn/ -> Main.java (source)

   1  /*    Copyright (C) 2005 Simon David Rycroft
   2  
   3      This program is free software; you can redistribute it and/or
   4      modify it under the terms of the GNU General Public License
   5      as published by the Free Software Foundation; either version 2
   6      of the License, or (at your option) any later version.
   7  
   8      This program is distributed in the hope that it will be useful,
   9      but WITHOUT ANY WARRANTY; without even the implied warranty of
  10      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11      GNU General Public License for more details.
  12  
  13      You should have received a copy of the GNU General Public License
  14      along with this program; if not, write to the Free Software
  15      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
  16  
  17  import java.awt.BorderLayout;
  18  import java.awt.Color;
  19  import java.awt.Container;
  20  
  21  import java.awt.Cursor;
  22  import java.awt.dnd.DropTargetListener;
  23  import java.awt.dnd.DropTargetDropEvent;
  24  import java.awt.dnd.DropTargetDragEvent;
  25  import java.awt.dnd.DropTargetEvent;
  26  import java.awt.dnd.DropTarget;
  27  import java.awt.dnd.DnDConstants;
  28  import java.awt.datatransfer.*;
  29  
  30  import java.awt.event.MouseEvent;
  31  import java.awt.event.MouseListener;
  32  import java.awt.GridLayout;
  33  import java.io.File;
  34  import java.io.PrintStream;
  35  import java.io.BufferedReader;
  36  import java.net.URL;
  37  import java.net.URI;
  38  import java.util.Arrays;
  39  import java.util.Iterator;
  40  import java.util.List;
  41  import java.util.Vector;
  42  import javax.swing.BorderFactory;
  43  import javax.swing.ImageIcon;
  44  import javax.swing.JApplet;
  45  import javax.swing.JButton;
  46  import javax.swing.JFileChooser;
  47  import javax.swing.JLabel;
  48  import javax.swing.JOptionPane;
  49  import javax.swing.JPanel;
  50  import javax.swing.JProgressBar;
  51  import javax.swing.JScrollPane;
  52  import javax.swing.JTable;
  53  import javax.swing.table.TableColumn;
  54  import javax.swing.UIManager;
  55  import javax.swing.SwingConstants;
  56  import netscape.javascript.JSObject;
  57  import javax.swing.JCheckBox;
  58  
  59  import java.net.MalformedURLException;
  60  import javax.print.DocFlavor.STRING;
  61  import javax.swing.UnsupportedLookAndFeelException;
  62  
  63  public class Main extends JApplet implements MouseListener, DropTargetListener {
  64  
  65      private JTable table;
  66      private JScrollPane scrollPane;
  67      private JPanel rightPanel;
  68      private JButton add,remove,upload,help;
  69      private ImageIcon dropIcon,dropIconUpload,dropIconAdded;    
  70      private TableData tabledata;
  71      private TableColumn sizeColumn;
  72      private File [] files;
  73      private JLabel progCompletion,iconLabel;
  74      private JProgressBar progBar;
  75      private int sentBytes,totalBytes,buttonClicked,maxPixels,percentComplete,maxFileSize, red, green, blue;
  76      private Color backgroundColour,columnHeadColourBack,
  77              columnHeadColourFore, tableForegroundColour,topbackgroundcolour, topforegroundcolour,
  78              rightbackgroundcolour, bottombackgroundcolour, bottomforegroundcolour;
  79      private PostletLabels pLabels;
  80      private Vector failedFiles,uploadedFiles;
  81      private UploadManager upMan;
  82      private JFileChooser chooser;
  83      private JCheckBox chkAutoUpload;
  84  
  85      javax.swing.JPanel pnlTop;
  86      javax.swing.JLabel jLabel1;
  87      javax.swing.JCheckBox chkUpload;
  88     
  89  
  90      // Default error PrintStream!
  91      private PrintStream out = System.out;
  92  
  93      // Boolean set to false when a javascript method is executed
  94      private boolean javascript;
  95  
  96      // Parameters
  97      private URL endPageURL, helpPageURL, destinationURL,dropImageURL,dropImageUploadURL,dropImageAddedURL;
  98      private boolean warnMessage,autoUpload,helpButton,failedFileMessage,addButton,removeButton,uploadButton;
  99      private String language, dropImage, dropImageAdded, dropImageUpload, proxy, fileToRemove;
 100      private int maxThreads;
 101      private String [] fileExtensions;
 102  
 103      // URI list flavor (Hack for linux/KDE)
 104      private DataFlavor uriListFlavor;
 105  
 106      // JSObject for doing the shit!
 107      private JSObject jso;
 108      
 109      // Javascript functions called by Postlet
 110      /**
 111       * postletStatus(int)
 112       *    sends the percentage complete status every time it changes
 113       * 
 114       * postletFinished()
 115       *    executed when postlet has finished uploading
 116       * 
 117       * postletFiles(string)
 118       *    sends a list of files queued for upload
 119       * 
 120       * postletError(int, string)
 121       *    Informs of an error, along with an optional text string
 122       *    int:
 123       *        0 - File too big
 124       *        1 - File wrong format
 125       *        2 - File corrupt (missing)
 126       *        3 - Upload failed
 127       */
 128      private static final String [] postletJS = {"postletStatus","postletFinished","postletFiles","postletError"};
 129      
 130  
 131      // Postlet Version (Mainly for diagnostics and tracking)
 132      public static final String postletVersion = "0.15";
 133  
 134      public void init() {
 135          // First thing, output the version, for debugging purposes.
 136          System.out.println("POSTLET VERSION: "+postletVersion);
 137          //String date = "$Date$";
 138          //System.out.println(date.substring(7,date.length()-1));
 139  
 140          // URI list flavor:
 141          try {
 142              uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
 143          }
 144          catch (ClassNotFoundException cnfe){
 145              errorMessage("No class found for DataFlavor");
 146          }
 147          
 148          // New JSObject for calling methods etc
 149          try {
 150              jso = (JSObject) JSObject.getWindow(this);
 151          }catch(netscape.javascript.JSException njjse){
 152              errorMessage("Unable to create JSO. Safari?");
 153          }
 154  
 155          // Set the javascript to false, and start listening for clicks
 156          javascript = false;
 157          JavascriptListener jsListen = new JavascriptListener(this);
 158          jsListen.start();
 159          buttonClicked = 0; // Default of add click.
 160          percentComplete = 0; // Just started, nothing done!
 161  
 162          getParameters();// Also sets pLabels
 163          layoutGui();
 164          //table.getTableHeader().setBackground(new java.awt.Color(66, 31, 171));
 165          //table.getTableHeader().setForeground(new java.awt.Color(164, 164, 164));
 166          table.setRowMargin(0);
 167          createChooser();
 168          // Vector of failedFiles
 169          failedFiles = new Vector();
 170          uploadedFiles = new Vector();
 171  
 172      }
 173  
 174      private void createChooser(){
 175          chooser = new JFileChooser();
 176  
 177          progBar.setValue(0);
 178          if (fileExtensions != null){
 179              UploaderFileFilter filter = new UploaderFileFilter();
 180              for (int i=1; i<fileExtensions.length; i++){
 181                  filter.addExtension(fileExtensions[i]);
 182              }
 183              filter.setDescription(fileExtensions[0]);
 184              chooser.addChoosableFileFilter(filter);
 185          }
 186          else {
 187              chooser.setFileFilter(chooser.getAcceptAllFileFilter());
 188          }
 189  
 190          chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
 191          chooser.setMultiSelectionEnabled(true);
 192          chooser.setDialogTitle(pLabels.getLabel(14));
 193      }
 194      private void layoutGui(){
 195          //JOptionPane.showMessageDialog(null, "This is a CVS version of Postlet, use with caution","CVS",JOptionPane.INFORMATION_MESSAGE);
 196          // Set the look of the applet
 197          try {
 198              UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
 199          } catch (UnsupportedLookAndFeelException exc){;} catch (IllegalAccessException exc){;} catch (ClassNotFoundException exc){;} catch (InstantiationException exc){;}
 200  
 201          // Get the main pane to add content to.
 202          Container pane = getContentPane();
 203          pane.setBackground(new java.awt.Color(210, 240, 0));
 204          // Attempt to add drop listener to the whole applet
 205          try {
 206              DropTarget dt = new DropTarget();
 207              dt.addDropTargetListener(this);
 208              pane.setDropTarget(dt);
 209          } catch (java.util.TooManyListenersException tmle){
 210              errorMessage( "Too many listeners to drop!");
 211          }
 212          // Table for the adding of Filenames and sizes to.
 213          pnlTop = new javax.swing.JPanel();
 214          progCompletion = new JLabel(pLabels.getLabel(10));
 215          //progCompletion.setForeground(new java.awt.Color(164, 164, 164));
 216          
 217          chkAutoUpload = new JCheckBox("auto upload", autoUpload);
 218          chkAutoUpload.setBackground(new java.awt.Color(210, 240, 0));
 219          chkAutoUpload.setForeground(new java.awt.Color(164, 164, 164));
 220          chkAutoUpload.addActionListener(new java.awt.event.ActionListener() {
 221              public void actionPerformed(java.awt.event.ActionEvent evt) {
 222                  chkAutoUploadActionPerformed(evt);
 223              }
 224          });
 225  
 226          javax.swing.GroupLayout pnlTopLayout = new javax.swing.GroupLayout(pnlTop);
 227          pnlTop.setLayout(pnlTopLayout);
 228         
 229  
 230          pnlTopLayout.setHorizontalGroup(
 231              pnlTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 232              .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlTopLayout.createSequentialGroup()
 233                  .addContainerGap()
 234                  .addComponent(chkAutoUpload)
 235                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 267, Short.MAX_VALUE)
 236                  //.addComponent(progCompletion)
 237                  .addContainerGap())
 238          );
 239          pnlTopLayout.setVerticalGroup(
 240              pnlTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 241              .addGroup(pnlTopLayout.createSequentialGroup()
 242                  .addGap(11, 11, 11)
 243                  .addGroup(pnlTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 244                      //.addComponent(progCompletion)
 245                      .addComponent(chkAutoUpload))
 246                  .addContainerGap())
 247          );
 248          pane.add(pnlTop, BorderLayout.NORTH);
 249          // progCompletion = new JLabel(pLabels.getLabel(10),SwingConstants.RIGHT);
 250          //pane.add(progCompletion, BorderLayout.NORTH);
 251          
 252          tabledata = new TableData(pLabels.getLabel(0),pLabels.getLabel(1));
 253          table = new JTable(tabledata);
 254  
 255          table.setBackground(new java.awt.Color(210, 240, 0));
 256  
 257          table.setColumnSelectionAllowed(false);
 258          table.setFillsViewportHeight(true);
 259          table.setGridColor(new java.awt.Color(102, 102, 102));
 260          //table.setDragEnabled(false); // This method is not available to Java 3!
 261          sizeColumn = table.getColumn(pLabels.getLabel(1));
 262          sizeColumn.setMaxWidth(100);
 263  
 264          table.getColumn(pLabels.getLabel(1)).setMinWidth(70);
 265          if (backgroundColour != null){            
 266              table.setBackground(backgroundColour);
 267              table.setGridColor(backgroundColour);
 268          }
 269          
 270          if (columnHeadColourBack != null){    
 271              table.getTableHeader().setBackground(columnHeadColourBack);
 272              table.getTableHeader().setBorder(BorderFactory.createEmptyBorder());
 273          }
 274          
 275          if (columnHeadColourFore != null){    
 276              table.getTableHeader().setForeground(columnHeadColourFore);
 277          }
 278          
 279          if (tableForegroundColour != null){    
 280              table.setForeground(tableForegroundColour);
 281          }
 282          
 283          if (topbackgroundcolour != null){    
 284              pnlTop.setBackground(topbackgroundcolour);
 285              chkAutoUpload.setBackground(topbackgroundcolour);
 286          }
 287          
 288          
 289          if (topforegroundcolour != null){
 290              pnlTop.setForeground(topforegroundcolour);
 291              chkAutoUpload.setForeground(topforegroundcolour);            
 292          }
 293  
 294          
 295  
 296  
 297          scrollPane = new JScrollPane(table);
 298          scrollPane.setBorder(BorderFactory.createEmptyBorder(1,0,1,0));
 299          
 300          
 301          if (backgroundColour != null){
 302              scrollPane.setBackground(backgroundColour);
 303          }
 304          // Always set the table background colour as White.
 305          // May change this if required, only would require alot of Params!
 306          scrollPane.getViewport().setBackground(Color.white);
 307          
 308          if (dropImageURL!=null){
 309              // Instead of the table, we'll add a lovely image to the center
 310              // of the applet to drop images on.
 311              dropIcon = new ImageIcon(dropImageURL);
 312              iconLabel = new JLabel(dropIcon);
 313              pane.add(iconLabel, BorderLayout.CENTER);            
 314          }
 315          else {
 316              // Add the scroll pane/table to the main pane
 317              pane.add(scrollPane, BorderLayout.CENTER);
 318          }
 319          
 320          //scrollPane.setColumnHeader(null);
 321          
 322          if (dropImageUploadURL!=null)
 323              dropIconUpload = new ImageIcon(dropImageUploadURL);
 324          if (dropImageAddedURL!=null)
 325              dropIconAdded = new ImageIcon(dropImageAddedURL);
 326  
 327          errorMessage("Adding button");
 328          if (helpButton)
 329              rightPanel = new JPanel(new GridLayout(4,1,5,5));
 330          else
 331              rightPanel = new JPanel(new GridLayout(3,1,5,5));
 332          rightPanel.setBorder(BorderFactory.createEmptyBorder(5,2,0,2));
 333          //rightPanel.setBackground(new java.awt.Color(210, 240, 0));
 334          add = new JButton();
 335  
 336  
 337          //add.setBackground(new java.awt.Color(210, 240, 0));
 338          add.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/filenew.png"))); // NOI18N
 339          add.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
 340          add.setContentAreaFilled(false);
 341          add.setFocusCycleRoot(true);
 342          add.setFocusable(false);
 343  
 344          add.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
 345  
 346          if(addButton){
 347              add.addMouseListener(this);
 348              rightPanel.add(add);
 349          }
 350  
 351          remove = new JButton();
 352          //remove.setBackground(new java.awt.Color(210, 240, 0));
 353          remove.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/delete.png"))); // NOI18N
 354          remove.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
 355          remove.setContentAreaFilled(false);
 356          remove.setFocusable(false);
 357          remove.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
 358          remove.setToolTipText("remove list file");
 359          if(removeButton){
 360              remove.addMouseListener(this);
 361              remove.setEnabled(false);
 362              rightPanel.add(remove);
 363          }
 364  
 365          upload = new JButton();
 366          
 367          upload.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/upload.png"))); // NOI18N
 368          upload.setAutoscrolls(true);
 369          upload.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
 370          upload.setContentAreaFilled(false);
 371          upload.setFocusable(false);
 372          upload.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
 373          upload.setToolTipText("upload file");
 374          if(uploadButton){
 375              upload.addMouseListener(this);
 376              upload.setEnabled(false);
 377              rightPanel.add(upload);
 378          }
 379  
 380          help = new JButton(pLabels.getLabel(9));
 381          help.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
 382          if (helpButton){
 383              help.addMouseListener(this);
 384              rightPanel.add(help);
 385          }
 386  
 387     
 388          
 389          if (backgroundColour != null)
 390              rightPanel.setBackground(backgroundColour);
 391          if(addButton || removeButton || helpButton || uploadButton)
 392              pane.add(rightPanel,"East");
 393  
 394          JPanel progPanel = new JPanel(new GridLayout(2, 1));
 395          progPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
 396  
 397          progPanel.setBackground(new java.awt.Color(210, 240, 0));
 398          progPanel.add(progCompletion);
 399          progBar = new JProgressBar();
 400          progBar.setStringPainted(true);
 401          progPanel.add(progBar,BorderLayout.EAST);
 402  
 403          progPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,50));
 404  
 405          if (backgroundColour != null){
 406              pane.setBackground(backgroundColour);
 407              //progPanel.setBackground(backgroundColour);
 408          }
 409  
 410          pane.add(progPanel,"South");
 411  
 412          if (rightbackgroundcolour != null){
 413              rightPanel.setBackground(rightbackgroundcolour);
 414              upload.setBackground(rightbackgroundcolour);
 415              remove.setBackground(rightbackgroundcolour);
 416              add.setBackground(rightbackgroundcolour);
 417          }
 418          
 419         if (bottombackgroundcolour != null){
 420              progPanel.setBackground(bottombackgroundcolour);
 421              progBar.setBackground(bottombackgroundcolour);
 422          
 423          }
 424  
 425         if (bottomforegroundcolour != null){
 426  
 427              progCompletion.setForeground(bottomforegroundcolour);
 428  
 429          }
 430  
 431  
 432          
 433  
 434          // If the destination has not been set/isn't a proper URL
 435          // Then deactivate the buttons. 
 436          if (destinationURL == null)
 437              add.setEnabled(false);
 438  
 439      }
 440  
 441          private void chkAutoUploadActionPerformed(java.awt.event.ActionEvent evt) {
 442              autoUpload = chkAutoUpload.isSelected();
 443              upload.setVisible(!autoUpload);
 444                  if(autoUpload && add.isEnabled()){
 445                  uploadClick();
 446              }
 447          }
 448  
 449      protected void errorMessage(String message){
 450          out.println("*** "+message+" ***");
 451      }
 452      // Helper method for getting the parameters from the webpage.
 453      private void getParameters(){
 454          
 455          /* MAX FILE SIZE */
 456          try {
 457              maxFileSize = Integer.parseInt(getParameter("maxfilesize"));
 458          } catch (NullPointerException nullMaxSize){
 459              errorMessage("maxfilesize is null");
 460              maxFileSize = Integer.MAX_VALUE;
 461          } catch (NumberFormatException nfemaxfilesize){
 462              errorMessage("maxfilesize is not a number");
 463              maxFileSize = Integer.MAX_VALUE;
 464          }
 465          
 466          /* PROXY */
 467          try {
 468              proxy = getParameter("proxy");
 469              if(proxy.equals("") || proxy.equals(null) || proxy.toLowerCase().equals("false")){
 470                  proxy = "";
 471              }
 472          } catch (NullPointerException nullProxy){
 473              proxy = "";
 474              errorMessage("proxy is null");
 475          }
 476  
 477          /* LANGUAGE */
 478          try {
 479              language = getParameter("language");
 480              if (language.equals("") || language.equals(null))
 481                  language = "EN";
 482          } catch (NullPointerException nullLang){
 483              // Default language being set
 484              language = "EN";
 485              errorMessage("language is null");
 486          }
 487      // This method (getParameters) relies on labels from PostletLabels if
 488      // there is an error.
 489          pLabels = new PostletLabels(language, getCodeBase());
 490  
 491          /* DESTINATION */
 492          try {
 493           destinationURL = new URL(getParameter("destination"));
 494           //Following line is for testing, and to hard code the applet to postlet.com
 495           //destinationURL = new URL("http://localhost/postlet/javaUpload.php"); //edit
 496          } catch(java.net.MalformedURLException malurlex){
 497              // Do something here for badly formed destination, which is ESENTIAL.
 498              errorMessage( "Badly formed destination:###"+getParameter("destination")+"###");
 499              JOptionPane.showMessageDialog(null, ""+pLabels.getLabel(3), ""+pLabels.getLabel(5), JOptionPane.ERROR_MESSAGE);
 500          } catch(java.lang.NullPointerException npe){
 501              // Do something here for the missing destination, which is ESENTIAL.
 502              errorMessage("destination is null");
 503              JOptionPane.showMessageDialog(null, pLabels.getLabel(4), pLabels.getLabel(5), JOptionPane.ERROR_MESSAGE);
 504          }
 505  
 506          /* BACKGROUND */
 507          try {
 508              //Integer bgci = new Integer(getParameter("backgroundcolour"));
 509              String str = new String(getParameter("backgroundcolour"));
 510              String[] arrStr = str.split(",");
 511              red = Integer.parseInt( arrStr[0].trim());
 512              green = Integer.parseInt( arrStr[1].trim());
 513              blue = Integer.parseInt( arrStr[2].trim());
 514              backgroundColour = new java.awt.Color(red, green, blue);
 515          } catch(NumberFormatException numfe){
 516              errorMessage( "background colour is not a number:###"+getParameter("backgroundcolour")+"###");
 517          } catch (NullPointerException nullred){
 518              errorMessage( "background colour is null");
 519          }
 520  
 521          /* tableForegroundColour */
 522          try {
 523              //Integer bgci = new Integer(getParameter("tableforegroundcolour"));
 524              String str = new String(getParameter("tableforegroundcolour"));
 525              String[] arrStr = str.split(",");
 526              red = Integer.parseInt( arrStr[0].trim());
 527              green = Integer.parseInt( arrStr[1].trim());
 528              blue = Integer.parseInt( arrStr[2].trim());
 529              tableForegroundColour = new java.awt.Color(red, green, blue);
 530          } catch(NumberFormatException numfe){
 531              errorMessage( "background colour is not a number:###"+getParameter("backgroundcolour")+"###");
 532          } catch (NullPointerException nullred){
 533              errorMessage( "background colour is null");
 534          }
 535  
 536          /* TABLEHEADERFOREGROUND */
 537          try {
 538              //Integer thfi = new Integer(getParameter("tableheaderforegroundcolour"));
 539              String str = new String(getParameter("tableheaderforegroundcolour"));
 540              String[] arrStr = str.split(",");
 541              red = Integer.parseInt( arrStr[0].trim());
 542              green = Integer.parseInt( arrStr[1].trim());
 543              blue = Integer.parseInt( arrStr[2].trim());
 544              columnHeadColourFore = new java.awt.Color(red, green, blue);
 545  
 546          } catch(NumberFormatException numfe){
 547              errorMessage( "table header colour is not a number:###"+getParameter("tableheadcolour")+"###");
 548          } catch (NullPointerException nullred){
 549              errorMessage( "table header colour is null");
 550          }
 551  
 552          /* TABLEHEADERBACKGROUND */
 553          try {
 554              //Integer thbi = new Integer(getParameter("tableheaderbackgroundcolour"));
 555              String str = new String(getParameter("tableheaderbackgroundcolour"));
 556              String[] arrStr = str.split(",");            
 557              red = Integer.parseInt( arrStr[0].trim());
 558              green = Integer.parseInt( arrStr[1].trim());
 559              blue = Integer.parseInt( arrStr[2].trim());
 560              columnHeadColourBack = new java.awt.Color(red, green, blue);
 561              
 562          } catch(NumberFormatException numfe){
 563              errorMessage( "table header back colour is not a number:###"+getParameter("tableheaderbackgroundcolour")+"###");
 564          } catch (NullPointerException nullred){
 565              errorMessage( "table header back colour is null");
 566          }
 567          
 568          /* topbackgroundcolour */
 569          try {
 570              //Integer thbi = new Integer(getParameter("topbackgroundcolour"));
 571              String str = new String(getParameter("topbackgroundcolour"));
 572              String[] arrStr = str.split(",");            
 573              red = Integer.parseInt( arrStr[0].trim());
 574              green = Integer.parseInt( arrStr[1].trim());
 575              blue = Integer.parseInt( arrStr[2].trim());
 576              topbackgroundcolour = new java.awt.Color(red, green, blue);
 577              
 578          } catch(NumberFormatException numfe){
 579              errorMessage( "table header back colour is not a number:###"+getParameter("tableheaderbackgroundcolour")+"###");
 580          } catch (NullPointerException nullred){
 581              errorMessage( "table header back colour is null");
 582          }
 583          
 584          /* topforegroundcolour */
 585          try {
 586              //Integer thbi = new Integer(getParameter("topforegroundcolour"));
 587              String str = new String(getParameter("topforegroundcolour"));
 588              String[] arrStr = str.split(",");            
 589              red = Integer.parseInt( arrStr[0].trim());
 590              green = Integer.parseInt( arrStr[1].trim());
 591              blue = Integer.parseInt( arrStr[2].trim());
 592              topforegroundcolour = new java.awt.Color(red, green, blue);
 593              
 594          } catch(NumberFormatException numfe){
 595              errorMessage( "table tableheaderbackgroundcolour is not a number:###"+getParameter("tableheaderbackgroundcolour")+"###");
 596          } catch (NullPointerException nullred){
 597              errorMessage( "table tableheaderbackgroundcolour colour is null");
 598          }
 599          
 600          try {
 601              //getParameter("bottomforegroundcolour")
 602              String str = new String(getParameter("bottomforegroundcolour"));
 603              String[] arrStr = str.split(",");            
 604              red = Integer.parseInt( arrStr[0].trim());
 605              green = Integer.parseInt( arrStr[1].trim());
 606              blue = Integer.parseInt( arrStr[2].trim());
 607              bottomforegroundcolour = new java.awt.Color(red, green, blue);
 608              
 609          } catch(NumberFormatException numfe){
 610              errorMessage( "table bottomforegroundcolour is not a number:###"+getParameter("bottomforegroundcolour")+"###");
 611          } catch (NullPointerException nullred){
 612              errorMessage( "table bottomforegroundcolourr is null");
 613          }
 614  
 615          try {
 616  
 617              String str = new String(getParameter("bottombackgroundcolour"));
 618              String[] arrStr = str.split(",");
 619              red = Integer.parseInt( arrStr[0].trim());
 620              green = Integer.parseInt( arrStr[1].trim());
 621              blue = Integer.parseInt( arrStr[2].trim());
 622              bottombackgroundcolour = new java.awt.Color(red, green, blue);
 623  
 624          } catch(NumberFormatException numfe){
 625              errorMessage( "table bottombackgroundcolour is not a number:###"+getParameter("bottomforegroundcolour")+"###");
 626          } catch (NullPointerException nullred){
 627              errorMessage( "table bottombackgroundcolour is null");
 628          }
 629  
 630           try {
 631  
 632              String str = new String(getParameter("rigthbackgroundcolour"));
 633              String[] arrStr = str.split(",");
 634              red = Integer.parseInt( arrStr[0].trim());
 635              green = Integer.parseInt( arrStr[1].trim());
 636              blue = Integer.parseInt( arrStr[2].trim());
 637              rightbackgroundcolour = new java.awt.Color(red, green, blue);
 638  
 639          } catch(NumberFormatException numfe){
 640              errorMessage( "table bottombackgroundcolour is not a number:###"+getParameter("rightbackgroundcolour")+"###");
 641          } catch (NullPointerException nullred){
 642              errorMessage( "table rightbackgroundcolour is null");
 643          }
 644  
 645  
 646  
 647  
 648  
 649  
 650  
 651          /* FILEEXTENSIONS */
 652          try {
 653              fileExtensions = getParameter("fileextensions").split(",");
 654          } catch(NullPointerException nullfileexts){
 655              errorMessage( "file extensions is null");
 656          }
 657  
 658          /* WARNINGMESSAGE */
 659          try {
 660              if (getParameter("warnmessage").toLowerCase().equals("true"))
 661                  warnMessage = true;
 662              else
 663                  warnMessage = false;
 664          } catch(NullPointerException nullwarnmessage){
 665              errorMessage( "warnmessage is null");
 666              warnMessage = false;
 667          }
 668  
 669          /* AUTOUPLOAD */
 670          try {
 671              if (getParameter("autoupload").toLowerCase().equals("true"))
 672                  autoUpload = true;
 673              else
 674                  autoUpload = false;
 675          } catch(NullPointerException nullwarnmessage){
 676              errorMessage( "autoUpload is null");
 677              autoUpload = false;
 678          }
 679  
 680          /* MAXTHREADS */
 681          try {
 682              Integer maxts = new Integer(getParameter("maxthreads"));
 683              maxThreads = maxts.intValue();
 684          } catch (NullPointerException nullmaxthreads){
 685              errorMessage( "maxthreads is null");
 686          } catch (NumberFormatException nummaxthreads){
 687              errorMessage( "maxthread is not a number");}
 688  
 689          /* ENDPAGE */
 690          try {
 691              endPageURL = new URL(getParameter("endpage"));
 692          } catch(java.net.MalformedURLException malurlex){
 693              errorMessage( "endpage is badly formed:###"+getParameter("endpage")+"###");
 694          } catch(java.lang.NullPointerException npe){
 695              errorMessage( "endpage is null");
 696          }
 697  
 698          /* HELPPAGE */
 699          try {
 700              helpPageURL = new URL(getParameter("helppage"));
 701          } catch(java.net.MalformedURLException malurlex){
 702              errorMessage( "helppage is badly formed:###"+getParameter("helppage")+"###");
 703          } catch(java.lang.NullPointerException npe){
 704              errorMessage( "helppage is null");
 705          }
 706  
 707          /* HELP BUTTON */
 708          try {
 709              if (getParameter("helpbutton").toLowerCase().trim().equals("true"))
 710                  helpButton = true;
 711              else
 712                  helpButton = false;
 713          } catch(NullPointerException nullwarnmessage){
 714              errorMessage( "helpbutton is null");
 715              helpButton = false;
 716          }
 717  
 718          /* ADD BUTTON */
 719          try {
 720              if (getParameter("addbutton").toLowerCase().trim().equals("false"))
 721                  addButton = false;
 722              else
 723                  addButton = true;
 724          } catch(NullPointerException nullwarnmessage){
 725              errorMessage( "addbutton is null");
 726              addButton = true;
 727          }
 728  
 729          /* REMOVE BUTTON */
 730          try {
 731              if (getParameter("removebutton").toLowerCase().trim().equals("false"))
 732                  removeButton = false;
 733              else
 734                  removeButton = true;
 735          } catch(NullPointerException nullwarnmessage){
 736              errorMessage( "removebutton is null");
 737              removeButton = true;
 738          }
 739  
 740          /* UPLOAD BUTTON */
 741          try {
 742              if (getParameter("uploadbutton").toLowerCase().trim().equals("false"))
 743                  uploadButton = false;
 744              else
 745                  uploadButton = true;
 746          } catch(NullPointerException nullwarnmessage){
 747              errorMessage( "uploadbutton is null");
 748              uploadButton = true;
 749          }
 750                  
 751          /* REPLACE TABLE WITH "DROP" IMAGE */
 752          try {
 753              dropImage = getParameter("dropimage");
 754              if (dropImage!=null)
 755                  dropImageURL = new URL(dropImage);
 756          } catch(MalformedURLException urlexception){
 757              try {
 758                  URL codeBase = getCodeBase();
 759                  dropImageURL = new URL(codeBase.getProtocol()+"://"+codeBase.getHost()+codeBase.getPath()+dropImage);
 760              } catch(MalformedURLException urlexception2){
 761                  errorMessage("dropimage is not a valid reference");
 762              }
 763          }
 764          /* REPLACE TABLE WITH "DROP" IMAGE (UPLOAD IMAGE)*/
 765          try {
 766              dropImageUpload = getParameter("dropimageupload");
 767              if (dropImageUpload!=null)
 768                  dropImageUploadURL = new URL(dropImageUpload);
 769          } catch(MalformedURLException urlexception){
 770              try {
 771                  URL codeBase = getCodeBase();
 772                  dropImageUploadURL = new URL(codeBase.getProtocol()+"://"+codeBase.getHost()+codeBase.getPath()+dropImageUpload);
 773              } catch(MalformedURLException urlexception2){
 774                  errorMessage("dropimageupload is not a valid reference");
 775              }
 776          }
 777          /* REPLACE TABLE WITH "DROP" IMAGE (ADDED IMAGE)*/
 778          try {
 779              dropImageAdded = getParameter("dropimageadded");
 780              if (dropImageAdded!=null)
 781                  dropImageAddedURL = new URL(dropImageAdded);
 782          } catch(MalformedURLException urlexception){
 783              try {
 784                  URL codeBase = getCodeBase();
 785                  dropImageAddedURL = new URL(codeBase.getProtocol()+"://"+codeBase.getHost()+codeBase.getPath()+dropImageAdded);
 786              } catch(MalformedURLException urlexception2){
 787                  errorMessage("dropimageupload is not a valid reference");
 788              }
 789          }
 790          
 791          /* FAILED FILES WARNING */
 792          // This should be set to false if failed files are being handled in
 793          // javascript
 794          try {
 795              if (getParameter("failedfilesmessage").toLowerCase().trim().equals("true"))
 796                  failedFileMessage = true;
 797              else
 798                  failedFileMessage = false;
 799          } catch (NullPointerException nullfailedfilemessage){
 800              errorMessage( "failedfilemessage is null");
 801              failedFileMessage = false;
 802          }
 803          
 804          /* MAX PIXELS FOR AN UPLOADED IMAGE */
 805          // This supports PNG, GIF and JPEG images only. All other images will
 806          // not be resized
 807          try {
 808              Integer maxps = new Integer(getParameter("maxpixels"));
 809              maxPixels = maxps.intValue();
 810          } catch (NullPointerException nullmaxpixels){
 811              errorMessage( "maxpixels is null");
 812          } catch (NumberFormatException nummaxpixels){
 813              errorMessage( "maxpixels is not a number");}
 814      }
 815      
 816      private void removeClick() {
 817          if(table.getSelectedRowCount()>0) {
 818              File [] fileTemp = new File[files.length-table.getSelectedRowCount()];
 819              int [] selectedRows = table.getSelectedRows();
 820              Arrays.sort(selectedRows);
 821              int k=0;
 822              for (int i=0; i<files.length;i++){
 823                  if (Arrays.binarySearch(selectedRows,i)<0){
 824                      fileTemp[k]=files[i];
 825                      k++;
 826                  }
 827              }
 828              files = fileTemp;
 829              tableUpdate();
 830          }
 831          if (files.length==0) {
 832              upload.setEnabled(false);
 833              remove.setEnabled(false);
 834          }
 835      }
 836  
 837      public void uploadClick() {
 838          if(files != null && files.length>0) {
 839              if (warnMessage){
 840                  JOptionPane.showMessageDialog(null, pLabels.getLabel(11), pLabels.getLabel(12), JOptionPane.INFORMATION_MESSAGE);
 841              }
 842              add.setEnabled(false);
 843              remove.setEnabled(false);
 844              help.setEnabled(false);
 845              upload.setEnabled(false);
 846              if (dropImageURL!=null && dropImageUploadURL!=null){
 847                  iconLabel.setIcon(dropIconUpload);
 848                  repaint();
 849              }
 850              sentBytes = 0;
 851              progBar.setMaximum(totalBytes);
 852              progBar.setMinimum(0);
 853              try {
 854                  upMan = new UploadManager(files, this, destinationURL, maxThreads);
 855              } catch(java.lang.NullPointerException npered){
 856                  upMan = new UploadManager(files, this, destinationURL);
 857              }
 858              upMan.start();
 859          }
 860      }
 861  
 862      protected synchronized void setProgress(int a) {
 863          if(totalBytes>0){
 864              sentBytes += a;
 865              progBar.setValue(sentBytes);
 866              if((sentBytes*100)/totalBytes>percentComplete){
 867                  percentComplete = (sentBytes*100)/totalBytes;
 868                  try {
 869                      jso.eval("try{"+postletJS[0]+"("+percentComplete+");}catch(e){;}");
 870                  } catch (netscape.javascript.JSException jseps){
 871                      errorMessage("Unable to send status to Javascript");
 872                  } catch (NullPointerException npe){
 873                      errorMessage("Unable to send status to Javascript");
 874                  }
 875              }
 876              if (sentBytes >= totalBytes){
 877                  if(sentBytes == totalBytes){
 878                      // Upload is complete. Check for failed files.
 879                      if (failedFiles.size()>0 && failedFileMessage){
 880                          // There is at least one failed file. Show an error message
 881                          String failedFilesString = "\r\n";
 882                          for (int i=0; i<failedFiles.size(); i++){
 883                              File tempFile = (File)failedFiles.elementAt(i);
 884                              failedFilesString += tempFile.getName()+"\r\n";
 885                          }
 886                          JOptionPane.showMessageDialog(null, pLabels.getLabel(16)+":"+failedFilesString,pLabels.getLabel(5), JOptionPane.ERROR_MESSAGE);
 887                      }
 888                      progCompletion.setText(pLabels.getLabel(2));
 889                      if (endPageURL != null){
 890                          errorMessage("Changing browser page");
 891                          getAppletContext().showDocument(endPageURL);
 892                      } else {
 893                          try {
 894                              // Just ignore this error, as it is most likely from the endpage
 895                              // not being set.
 896                              // Attempt at calling Javascript after upload is complete.
 897                              errorMessage("Executing: "+postletJS[1]+"();");
 898                              jso.eval("try{"+postletJS[1]+"();}catch(e){;}");
 899                          }
 900                          catch (netscape.javascript.JSException jse){
 901                              // Not to worry, just means the end page and a postletFinished
 902                              // method aren't set. Just finish, and let the web page user
 903                              // exit the page
 904                              errorMessage("postletFinished, and End page unset");
 905                          }
 906                          catch (NullPointerException npe){
 907                              errorMessage("postletFinished, and End page unset, and JS not executed");
 908                          }
 909                      }
 910                  }
 911                  // Reset the applet
 912                  totalBytes = 0;
 913                  percentComplete = 0;
 914                  progBar.setValue(0);
 915                  files = new File[0];
 916                  tableUpdate();
 917                  add.setEnabled(true);
 918                  help.setEnabled(true);
 919                  if (dropImageURL!=null && dropImageUploadURL!=null){
 920                      iconLabel.setIcon(dropIcon);
 921                  }
 922                  failedFiles.clear();
 923                  uploadedFiles.clear();
 924                  repaint();
 925  
 926              }
 927          }
 928      }
 929      
 930      // Get and set the proxy server
 931      public String getProxy(){
 932          return proxy;
 933      }
 934      
 935      public void setProxy(String p){
 936          proxy = p;
 937      }
 938  
 939      // Adds a file that HASN'T uploaded to an array. Once uploading is complete,
 940      // these can be listed with a popup box.
 941      public void addFailedFile(File f){
 942          failedFiles.add(f);
 943      }
 944  
 945      // Adds a file that HAS uploaded to an array. These are passed along with
 946      // failed files to a javascript method.
 947      public void addUploadedFile(File f){
 948          uploadedFiles.add(f);
 949      }
 950  
 951      public int getMaxPixels(){
 952          return maxPixels;
 953      }
 954      
 955      public void setMaxPixels(int pixels){
 956          maxPixels = pixels;
 957      }
 958      
 959      public int getMaxFileSize(){
 960          return maxFileSize;
 961      }
 962      
 963      public void setMaxFileSize(int f){
 964          maxFileSize = f;
 965      }
 966  
 967      private void tableUpdate() {
 968          totalBytes = 0;
 969          String [] filenames = new String[files.length];
 970          int [] fileSize = new int[files.length];
 971          for(int i=0; i<files.length; i++) {
 972              filenames[i] = files[i].getAbsolutePath();
 973              fileSize[i] = (int)files[i].length();
 974              totalBytes += (int)files[i].length();
 975          }
 976          int i=0;
 977          // FIXME - THIS SEEMS SILLY!********************************************
 978          String [][] rowData = new String[files.length][2];
 979          while(i<files.length) {
 980              rowData[i][0] = files[i].getName();
 981              rowData[i][1] = ""+files[i].length();
 982              i++;
 983          }
 984          // *********************************************************************
 985          tabledata.formatTable(rowData,i);
 986          sizeColumn.setMaxWidth(100);
 987          sizeColumn.setMinWidth(100);
 988          repaint();
 989      }
 990  
 991      public void addClick() {
 992          progCompletion.setText(pLabels.getLabel(10));
 993          int returnVal = chooser.showOpenDialog(null);
 994          if (returnVal == JFileChooser.APPROVE_OPTION) {
 995              File [] tempFiles = chooser.getSelectedFiles();
 996              Vector filesForUpload = new Vector();
 997              for (int i=0; i<tempFiles.length; i++){
 998                  if (tempFiles[i].isDirectory()){
 999                      File [] subDirFiles = tempFiles[i].listFiles();
1000                      for (int j = 0; j<subDirFiles.length; j++){
1001                          if (subDirFiles[j].isFile()){
1002                              if(subDirFiles[j].length()<maxFileSize){
1003                                  filesForUpload.add(subDirFiles[j]);
1004                              } else {
1005                                  fileTooBig(subDirFiles[j]);
1006                              }
1007                          }
1008                      }
1009  
1010                  } else {
1011                      if(tempFiles[i].length()<maxFileSize){
1012                          filesForUpload.add(tempFiles[i]);
1013                      } else {
1014                          fileTooBig(tempFiles[i]);
1015                      }
1016                  }
1017              }
1018              if (files == null){
1019                  files = new File[0];
1020              }
1021              tempFiles = new File[filesForUpload.size()+files.length];
1022              for (int i=0; i<files.length; i++)
1023                  tempFiles[i] = files[i];
1024              for (int i=0; i<filesForUpload.size(); i++){
1025                  tempFiles[i+files.length] = (File)filesForUpload.elementAt(i);
1026              }
1027              files = tempFiles;
1028              tableUpdate();
1029          }
1030          if (files != null && files.length>0) {
1031              upload.setEnabled(true);
1032              remove.setEnabled(true);            
1033              if (dropImageURL!=null && dropImageAddedURL!=null){
1034                  iconLabel.setIcon(dropIconAdded);
1035                  repaint();
1036              }
1037              try {
1038                  jso.eval("try{"+postletJS[2]+"('"+getFiles()+"');}catch(e){;}");
1039              } catch(netscape.javascript.JSException jsepf){
1040                  errorMessage("Unable to send info about files added");
1041              } catch(NullPointerException npe){
1042                  errorMessage("Unable to send info about files added");
1043              }
1044          }
1045          if (files !=null && autoUpload){
1046              uploadClick();
1047          }
1048          createChooser();// Not sure if this is necesary. FIXME
1049      }
1050      
1051      public void fileTooBig(File f){
1052          errorMessage("file too big: "+f.getName()+" - "+f.length());
1053          if(warnMessage){
1054              JOptionPane.showMessageDialog(null, ""+pLabels.getLabel(1)+" - "+f.getName(), ""+pLabels.getLabel(5), JOptionPane.ERROR_MESSAGE);
1055          }
1056          addFailedFile(f);
1057          try{
1058              jso.eval("try{"+postletJS[3]+"(0,'"+f.getName().replace("'","`")+"');}catch(e){;}");
1059          } catch(netscape.javascript.JSException jsepf){
1060              errorMessage("Unable to send info about 'file too big'");
1061          } catch(NullPointerException npe){
1062              errorMessage("Unable to send info about 'file too big'");
1063          }
1064      }
1065          
1066      public void fileNotAllowed(File f){
1067          errorMessage("file not allowed: "+f.getName());
1068          addFailedFile(f);
1069          try{
1070              jso.eval("try{"+postletJS[3]+"(1,'"+f.getName().replace("'","`")+"');}catch(e){;}");
1071          } catch(netscape.javascript.JSException jsepf){
1072              errorMessage("Unable to send info about 'file not allowed'");
1073          }
1074      }
1075      
1076      public void fileNotFound(File f){
1077          errorMessage("file not found: "+f.getName());
1078          addFailedFile(f);
1079          try{
1080              jso.eval("try{"+postletJS[3]+"(2,'"+f.getName().replace("'","`")+"');}catch(e){;}");
1081          } catch(netscape.javascript.JSException jsepf){
1082              errorMessage("Unable to send info about 'file not found'");
1083          } catch(NullPointerException npe){
1084              errorMessage("Unable to send info about 'file not found'");
1085          }
1086      }
1087      
1088      public void fileUploadFailed(File f){
1089          errorMessage("file upload failed: "+f.getName());
1090          addFailedFile(f);
1091          try{
1092              jso.eval("try{"+postletJS[3]+"(3,'"+f.getName().replace("'","`")+"');}catch(e){;}");
1093          } catch(netscape.javascript.JSException jsepf){
1094              errorMessage("Unable to send info about 'file upload failed'");
1095          } catch(NullPointerException npe){
1096              errorMessage("Unable to send info about 'file upload failed'");
1097          }
1098      }
1099  
1100      public void helpClick() {
1101          // Open a web page in another frame/window
1102          // Unless specified as a parameter, this will be a help page
1103          // on the postlet website.
1104  
1105          try {
1106              getAppletContext().showDocument(helpPageURL, "_blank");
1107          } catch (NullPointerException nohelppage){
1108              // Show a popup with help instead!
1109              try {getAppletContext().showDocument(new URL("http://www.postlet.com/help/"), "_blank");}catch(MalformedURLException mfue){;}// Hard coded URL, no need for catch
1110          }
1111  
1112      }
1113  
1114      public String getCookie(){
1115  
1116          // Method reads the cookie in from the Browser using the LiveConnect object.
1117          // May also add an option to set the cookie using an applet parameter FIXME!
1118          try {
1119              String cookie = new String();
1120              cookie = (String)jso.eval("try{document.cookie;}catch(e){;}");
1121              errorMessage("Cookie is:###"+cookie+"###");
1122              return cookie;
1123          }
1124          catch (Exception e){
1125              errorMessage("Failed to get cookie");
1126              return "";
1127          }
1128      }
1129      
1130      /**
1131       * Cancel all upload of files.
1132       */
1133      public void cancelUpload(){
1134          upMan.cancelUpload();
1135          errorMessage("Canceled upload");
1136          if(totalBytes>0){
1137              setProgress(totalBytes+1);
1138          }
1139      }
1140      /**
1141       * This method has been altered due to IE (and Safari) being shite
1142       * (it did return an array - oh well, backwards stepping).
1143       */
1144      public String getFailedFiles(){
1145          if (failedFiles.size()>0){
1146              String failedFilesString = "";
1147              // Return a "/" delimited string (as "/" is not a legal character).
1148              for(int i=0; i<failedFiles.size(); i++){
1149                  File tempFile = (File)failedFiles.elementAt(i);
1150                  failedFilesString += tempFile.getName()+"/";
1151              }
1152              return failedFilesString.replace("'","`");
1153              /*
1154              String [] arrayFailedFiles = new String[failedFiles.size()];
1155              for (int i=0; i<failedFiles.size(); i++){
1156                  File tempFile = (File)failedFiles.elementAt(i);
1157                  arrayFailedFiles[i] = tempFile.getName();
1158              }
1159              return arrayFailedFiles;
1160              */
1161          }
1162          return null;
1163      }
1164      
1165      /**
1166       * This method returns all the files that have been added to Postlet
1167       */
1168      public String getFiles(){
1169          String fileString = ""+files.length;
1170          for(int i=0; i<files.length; i++){
1171              fileString += "/"+files[i].getName();
1172          }
1173          return fileString.replace("'","`");
1174      }
1175  
1176      public String getUploadedFiles(){
1177          if (uploadedFiles.size()>0){
1178              String uploadedFilesString = "";
1179              // Return a "/" delimited string (as "/" is not a legal character).
1180              for(int i=0; i<uploadedFiles.size(); i++){
1181                  File tempFile = (File)uploadedFiles.elementAt(i);
1182                  uploadedFilesString += tempFile.getName()+"/";
1183              }
1184              return uploadedFilesString.replace("'","`");
1185              /*
1186              String [] arrayUploadedFiles = new String[uploadedFiles.size()];
1187              for (int i=0; i<uploadedFiles.size(); i++){
1188                  File tempFile = (File)uploadedFiles.elementAt(i);
1189                  arrayUploadedFiles[i] = tempFile.getName();
1190              }
1191              return arrayUploadedFiles;
1192              */
1193          }
1194          return null;
1195      }
1196      
1197      public void changedDestination(String destination){
1198          // Change the destination before upload.
1199          try {
1200              destinationURL = new URL(destination);
1201          } catch(java.net.MalformedURLException malurlex){
1202              // Do something here for badly formed destination, which is ESENTIAL.
1203              errorMessage( "Badly formed destination:###"+destination+"###");
1204              JOptionPane.showMessageDialog(null, ""+pLabels.getLabel(3), ""+pLabels.getLabel(5), JOptionPane.ERROR_MESSAGE);
1205          } catch(java.lang.NullPointerException npe){
1206              // Do something here for the missing destination, which is ESENTIAL.
1207              errorMessage("destination is null");
1208              JOptionPane.showMessageDialog(null, pLabels.getLabel(4), pLabels.getLabel(5), JOptionPane.ERROR_MESSAGE);
1209          }
1210      }
1211      
1212      protected void doRemoveFile(String number){
1213          try {
1214              int fileNumber = Integer.parseInt(number);
1215              if(files.length>fileNumber && fileNumber>-1){
1216                  File [] fileTemp = new File[files.length-1];
1217                  int j=0;
1218                  for(int i=0;i<files.length;i++){
1219                      if(i!=fileNumber){
1220                          fileTemp[j] = files[i];
1221                          j++;
1222                      }
1223                  }
1224                  files = fileTemp;
1225                  tableUpdate();
1226                  if (files.length==0) {
1227                      upload.setEnabled(false);
1228                      remove.setEnabled(false);
1229                  }
1230              }
1231              try {
1232                  jso.eval("try{"+postletJS[2]+"('"+getFiles()+"');}catch(e){;}");
1233              } catch(netscape.javascript.JSException jsepf){
1234                  errorMessage("Unable to send info about files added");
1235              } catch(NullPointerException npe){
1236                  errorMessage("Unable to send info about files added");
1237              }
1238          } catch (NumberFormatException nfe){
1239              errorMessage("removeFile not a number");
1240          }
1241      }
1242  
1243      public void postletAdd(){
1244  
1245          // Set a variable so that the listening thread can call the add click method
1246          buttonClicked = 0;
1247          javascript = true;
1248      }
1249      public void removeFile(String number){
1250          // As above
1251          buttonClicked = 3;
1252          fileToRemove = number;
1253          javascript = true;
1254      }
1255      public String getFileToRemove(){
1256          return fileToRemove;
1257      }
1258      public void postletUpload(){
1259          // As above
1260          buttonClicked = 1;
1261          javascript = true;
1262      }
1263      public void postletCancel(){
1264          // As above
1265          buttonClicked = 2;
1266          javascript = true;
1267      }
1268      public boolean getJavascriptStatus(){
1269  
1270          return javascript;
1271      }
1272      public void setJavascriptStatus(){
1273  
1274          javascript = false;
1275      }
1276      public boolean isUploadEnabled(){
1277  
1278          return upload.isEnabled();
1279      }
1280      public boolean isAddEnabled(){
1281  
1282          return add.isEnabled();
1283      }
1284      public boolean isRemoveEnabled(){
1285  
1286          return remove.isEnabled();
1287      }
1288      public int getButtonClicked(){
1289  
1290          return buttonClicked;
1291      }
1292  
1293      public void mouseClicked(MouseEvent e) {
1294          if(e.getSource()==add && add.isEnabled())        {addClick();}
1295          if(e.getSource()==upload && upload.isEnabled())    {uploadClick();}
1296          if(e.getSource()==remove && remove.isEnabled())    {removeClick();}
1297          if(e.getSource()==help && help.isEnabled())        {helpClick();}
1298      }
1299  
1300      public void drop(DropTargetDropEvent dtde) {      
1301          if(add.isEnabled())
1302             dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
1303          else
1304              dtde.acceptDrop(DnDConstants.ACTION_NONE);
1305          Transferable trans = dtde.getTransferable();
1306          try {
1307          java.awt.datatransfer.DataFlavor dataFlavour [];
1308          dataFlavour = dtde.getCurrentDataFlavors();
1309          String mimeType;
1310          Vector filesFromDrop = new Vector();
1311          boolean filesFound = false;
1312          while (!filesFound){
1313              for (int i=0; i<dataFlavour.length; i++){/*
1314                  mimeType = dataFlavour[i].getMimeType();
1315                  System.out.println(i+": "+dataFlavour[i].toString());
1316                  System.out.println(i+": "+mimeType);
1317                  System.out.println(i+": "+dataFlavour[i].getPrimaryType());
1318                  System.out.println(i+": "+dataFlavour[i].getHumanPresentableName());
1319                  System.out.println(i+": "+dataFlavour[i].getSubType());*/
1320                  if (dataFlavour[i].isFlavorJavaFileListType()){
1321                      // Windows
1322                      errorMessage("Windows D'n'D");
1323                      List listOfFiles = (List)trans.getTransferData(DataFlavor.javaFileListFlavor);
1324                      Iterator iter = listOfFiles.iterator();
1325                      while (iter.hasNext()) {
1326                          File tempFile = (File) iter.next();
1327                          filesFromDrop.add(tempFile);
1328                      }
1329                      filesFound = true;
1330                  } else if (dataFlavour[i].equals(uriListFlavor)){
1331                      // Linux
1332                      errorMessage("Linux (Mac?) D'n'D");
1333                      BufferedReader in = new BufferedReader(dataFlavour[i].getReaderForText(trans));
1334                      String line = in.readLine();
1335                      while(line!=null && !line.equals("")){
1336                          try {
1337                              File tempFile = new File(new URI(line));
1338                              filesFromDrop.add(tempFile);
1339                          }
1340                          catch (java.net.URISyntaxException usee){;}
1341                          catch (java.lang.IllegalArgumentException iae){;}
1342                          line = in.readLine();
1343                      }
1344                      filesFound = true;
1345                  }
1346              }
1347          }
1348          File [] tempFiles = new File[filesFromDrop.size()];
1349          filesFromDrop.copyInto(tempFiles);
1350          Vector filesForUpload = new Vector();
1351          for (int j=0; j<tempFiles.length; j++){
1352              if (tempFiles[j].isDirectory()){
1353                  File [] subDirFiles = tempFiles[j].listFiles();
1354                  for (int k = 0; k<subDirFiles.length; k++){
1355                      if (subDirFiles[k].isFile())
1356                          filesForUpload.add(subDirFiles[k]);
1357                  }
1358  
1359              } else
1360              filesForUpload.add(tempFiles[j]);
1361          }
1362          if (files == null){
1363              files = new File[0];
1364          }
1365          tempFiles = new File[filesForUpload.size()+files.length];
1366          for (int j=0; j<files.length; j++)
1367              tempFiles[j] = files[j];
1368          for (int j=0; j<filesForUpload.size(); j++){
1369              tempFiles[j+files.length] = (File)filesForUpload.elementAt(j);
1370          }
1371          files = tempFiles;
1372          tableUpdate();
1373  
1374          if (files != null && files.length>0) {
1375              errorMessage("Enabling the upload and remove buttons");
1376              upload.setEnabled(true);
1377              remove.setEnabled(true);
1378          }
1379          if (files !=null && autoUpload){
1380              uploadClick();
1381          }
1382  
1383          }
1384          catch (java.awt.datatransfer.UnsupportedFlavorException usfe){;}
1385          catch (java.io.IOException ioe){;}
1386          dtde.dropComplete(true);
1387      }
1388  
1389      public void dropActionChanged(DropTargetDragEvent dtde){;}
1390      public void dragOver(DropTargetDragEvent dtde){;}
1391      public void dragExit(DropTargetEvent dte){;}
1392      public void dragEnter(DropTargetDragEvent dtde){;}
1393  
1394      public void mouseEntered(MouseEvent e){;}
1395      public void mouseExited(MouseEvent e){;}
1396      public void mousePressed(MouseEvent e){;}
1397      public void mouseReleased(MouseEvent e){;}
1398  
1399  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7