Clover coverage report - DrJava Test Coverage (drjava-20120304-r5456)
Coverage timestamp: Sun Mar 4 2012 03:13:23 CST
file stats: LOC: 129   Methods: 8
NCLOC: 68   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
VectorFileOptionComponent.java 0% 38.7% 62.5% 30.9%
coverage coverage
 1    /*BEGIN_COPYRIGHT_BLOCK
 2    *
 3    * Copyright (c) 2001-2010, JavaPLT group at Rice University (drjava@rice.edu)
 4    * All rights reserved.
 5    *
 6    * Redistribution and use in source and binary forms, with or without
 7    * modification, are permitted provided that the following conditions are met:
 8    * * Redistributions of source code must retain the above copyright
 9    * notice, this list of conditions and the following disclaimer.
 10    * * Redistributions in binary form must reproduce the above copyright
 11    * notice, this list of conditions and the following disclaimer in the
 12    * documentation and/or other materials provided with the distribution.
 13    * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
 14    * names of its contributors may be used to endorse or promote products
 15    * derived from this software without specific prior written permission.
 16    *
 17    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 18    * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 19    * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 20    * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 21    * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 22    * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 23    * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 24    * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 25    * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 26    * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 27    * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 28    *
 29    * This software is Open Source Initiative approved Open Source Software.
 30    * Open Source Initative Approved is a trademark of the Open Source Initiative.
 31    *
 32    * This file is part of DrJava. Download the current version of this project
 33    * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
 34    *
 35    * END_COPYRIGHT_BLOCK*/
 36   
 37    package edu.rice.cs.drjava.ui.config;
 38   
 39   
 40    import java.awt.event.*;
 41    import java.io.File;
 42    import javax.swing.filechooser.FileFilter;
 43    import javax.swing.*;
 44   
 45    import java.util.Vector;
 46    import java.util.List;
 47   
 48    import edu.rice.cs.drjava.ui.*;
 49    import edu.rice.cs.drjava.config.*;
 50    import edu.rice.cs.util.swing.SwingFrame;
 51   
 52    /** Graphical form of a VectorOption for the Extra Classpath/Sourcepath options.
 53    * Uses a file chooser for each File element.
 54    * @version $Id: VectorFileOptionComponent.java 5246 2010-05-07 19:10:44Z mgricken $
 55    */
 56    public class VectorFileOptionComponent extends VectorOptionComponent<File> implements OptionConstants {
 57    private JFileChooser _jfc;
 58    protected File _baseDir = null;
 59   
 60  3 public VectorFileOptionComponent(VectorOption<File> opt, String text, SwingFrame parent) {
 61  3 this(opt, text, parent, null);
 62    }
 63   
 64    /** Constructor that allows for a tooltip description. */
 65  3 public VectorFileOptionComponent(VectorOption<File> opt, String text, SwingFrame parent, String description) {
 66  3 this(opt, text, parent, description, false);
 67    }
 68   
 69    /** Constructor with flag for move buttons. */
 70  79 public VectorFileOptionComponent(VectorOption<File> opt, String text, SwingFrame parent,
 71    String description, boolean moveButtonEnabled) {
 72  79 super(opt, text, parent, new String[] { }, description, moveButtonEnabled); // creates all four buttons
 73   
 74    // set up JFileChooser
 75  79 File workDir = new File(System.getProperty("user.home"));
 76   
 77  79 _jfc = new JFileChooser(workDir);
 78  79 _jfc.setDialogTitle("Select");
 79  79 _jfc.setApproveButtonText("Select");
 80  79 _jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
 81  79 _jfc.setMultiSelectionEnabled(true);
 82  79 _jfc.setFileFilter(ClassPathFilter.ONLY);
 83    }
 84   
 85    /** Sets the directory where the chooser will start if no file is selected. */
 86  0 public void setBaseDir(File f) {
 87  0 if (f.isDirectory()) { _baseDir = f; }
 88    }
 89   
 90    /** Shows a file chooser for adding a file to the element. */
 91  0 public void chooseFile() {
 92  0 int[] rows = _table.getSelectedRows();
 93  0 File selection = (rows.length==1)?_data.get(rows[0]):null;
 94  0 if (selection != null) {
 95  0 File parent = selection.getParentFile();
 96  0 if (parent != null) {
 97  0 _jfc.setCurrentDirectory(parent);
 98    }
 99    }
 100    else {
 101  0 if (_baseDir != null) { _jfc.setCurrentDirectory(_baseDir); }
 102    }
 103   
 104  0 File[] c = null;
 105  0 int returnValue = _jfc.showDialog(_parent, null);
 106  0 if (returnValue == JFileChooser.APPROVE_OPTION) {
 107  0 c = _jfc.getSelectedFiles();
 108    }
 109  0 if (c != null) {
 110  0 _table.getSelectionModel().clearSelection();
 111  0 for(int i = 0; i < c.length; i++) {
 112  0 _addValue(c[i]);
 113    }
 114    }
 115    }
 116   
 117    /** @return the file chooser */
 118  38 public JFileChooser getFileChooser() {
 119  38 return _jfc;
 120    }
 121   
 122  79 protected Action _getAddAction() {
 123  79 return new AbstractAction("Add") {
 124  0 public void actionPerformed(ActionEvent ae) {
 125  0 chooseFile();
 126    }
 127    };
 128    }
 129    }