Clover coverage report - DrJava Test Coverage (drjava-20120304-r5456)
Coverage timestamp: Sun Mar 4 2012 03:13:23 CST
file stats: LOC: 184   Methods: 16
NCLOC: 117   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
VectorAbsRelFileOptionComponent.java 0% 0% 0% 0%
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 edu.rice.cs.util.AbsRelFile;
 43    import javax.swing.filechooser.FileFilter;
 44    import javax.swing.*;
 45    import javax.swing.table.*;
 46   
 47    import java.util.Vector;
 48    import java.util.List;
 49   
 50    import edu.rice.cs.drjava.ui.*;
 51    import edu.rice.cs.drjava.config.*;
 52    import edu.rice.cs.util.swing.SwingFrame;
 53    import edu.rice.cs.util.swing.CheckBoxJList;
 54   
 55    /** Graphical form of a VectorOption for the Extra Classpath/Sourcepath options.
 56    * Uses a file chooser for each AbsRelFile element.
 57    * @version $Id: VectorAbsRelFileOptionComponent.java 5236 2010-04-27 01:43:36Z mgricken $
 58    */
 59    public class VectorAbsRelFileOptionComponent extends VectorOptionComponent<AbsRelFile> implements OptionConstants {
 60    private FileFilter _fileFilter;
 61    private JFileChooser _jfc;
 62    protected File _baseDir = null;
 63   
 64  0 public VectorAbsRelFileOptionComponent (VectorOption<AbsRelFile> opt, String text, SwingFrame parent) {
 65  0 this(opt, text, parent, null);
 66    }
 67   
 68    /** Constructor that allows for a tooltip description. */
 69  0 public VectorAbsRelFileOptionComponent (VectorOption<AbsRelFile> opt, String text, SwingFrame parent, String description) {
 70  0 this(opt, text, parent, description, false);
 71    }
 72   
 73    /** Constructor with flag for move buttons. */
 74  0 public VectorAbsRelFileOptionComponent (VectorOption<AbsRelFile> opt, String text, SwingFrame parent,
 75    String description, boolean moveButtonEnabled) {
 76  0 super(opt, text, parent, new String[] { "File", "Absolute" }, description, moveButtonEnabled); // creates all four buttons
 77   
 78    // Absolute column
 79  0 _table.getColumnModel().getColumn(1).setMinWidth(80);
 80  0 _table.getColumnModel().getColumn(1).setMaxWidth(80);
 81   
 82    // set up JFileChooser
 83  0 File workDir = new File(System.getProperty("user.home"));
 84   
 85  0 _jfc = new JFileChooser(workDir);
 86  0 _jfc.setDialogTitle("Select");
 87  0 _jfc.setApproveButtonText("Select");
 88  0 _jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
 89  0 _jfc.setMultiSelectionEnabled(true);
 90  0 _fileFilter = ClassPathFilter.ONLY;
 91   
 92  0 final TableCellRenderer renderer = _table.getTableHeader().getDefaultRenderer();
 93  0 int w = renderer.getTableCellRendererComponent(_table,_table.getModel().getColumnName(1), false, false, 0, 1).getPreferredSize().width;
 94  0 _table.getColumnModel().getColumn(1).setPreferredWidth(w);
 95    }
 96   
 97    /** Returns the table model. Can be overridden by subclasses. */
 98  0 protected AbstractTableModel _makeTableModel() {
 99  0 return new AbstractTableModel() {
 100  0 public String getColumnName(int col) { return (_columnNames.length == 0)?super.getColumnName(col):_columnNames[col]; }
 101  0 public int getRowCount() { return _data.size(); }
 102  0 public int getColumnCount() { return 2; }
 103  0 public Object getValueAt(int row, int col) {
 104  0 switch(col) {
 105  0 case 0: return _data.get(row);
 106  0 case 1: return _data.get(row).keepAbsolute();
 107    }
 108  0 throw new IllegalArgumentException("Illegal column");
 109    }
 110  0 public Class<?> getColumnClass(int col) {
 111  0 switch(col) {
 112  0 case 0: return String.class;
 113  0 case 1: return Boolean.class;
 114    }
 115  0 throw new IllegalArgumentException("Illegal column");
 116    }
 117  0 public boolean isCellEditable(int row, int col) {
 118  0 if (col<1) {
 119  0 return false;
 120    } else {
 121  0 return true;
 122    }
 123    }
 124  0 public void setValueAt(Object value, int row, int col) {
 125  0 AbsRelFile f = _data.get(row);
 126  0 switch(col) {
 127  0 case 1:
 128  0 f.keepAbsolute((Boolean)value);
 129  0 break;
 130  0 default:
 131  0 throw new IllegalArgumentException("Illegal column");
 132    }
 133  0 fireTableCellUpdated(row, col);
 134    }
 135    };
 136    }
 137   
 138    /** Set the file filter for this vector option component. */
 139  0 public void setFileFilter(FileFilter fileFilter) {
 140  0 _fileFilter = fileFilter;
 141    }
 142   
 143    /** Sets the directory where the chooser will start if no file is selected. */
 144  0 public void setBaseDir(File f) {
 145  0 if (f.isDirectory()) { _baseDir = f; }
 146    }
 147   
 148    /** Shows a file chooser for adding a file to the element. */
 149  0 public void chooseFile() {
 150  0 int[] rows = _table.getSelectedRows();
 151  0 File selection = (rows.length==1)?_data.get(rows[0]):null;
 152  0 if (selection != null) {
 153  0 File parent = selection.getParentFile();
 154  0 if (parent != null) {
 155  0 _jfc.setCurrentDirectory(parent);
 156    }
 157    }
 158    else {
 159  0 if (_baseDir != null) { _jfc.setCurrentDirectory(_baseDir); }
 160    }
 161   
 162  0 _jfc.setFileFilter(_fileFilter);
 163   
 164  0 File[] c = null;
 165  0 int returnValue = _jfc.showDialog(_parent, null);
 166  0 if (returnValue == JFileChooser.APPROVE_OPTION) {
 167  0 c = _jfc.getSelectedFiles();
 168    }
 169  0 if (c != null) {
 170  0 _table.getSelectionModel().clearSelection();
 171  0 for(int i = 0; i < c.length; i++) {
 172  0 _addValue(new AbsRelFile(c[i]));
 173    }
 174    }
 175    }
 176   
 177  0 protected Action _getAddAction() {
 178  0 return new AbstractAction("Add") {
 179  0 public void actionPerformed(ActionEvent ae) {
 180  0 chooseFile();
 181    }
 182    };
 183    }
 184    }