Clover coverage report - DrJava Test Coverage (drjava-20110828-r5448)
Coverage timestamp: Sun Aug 28 2011 03:13:33 CDT
file stats: LOC: 131   Methods: 13
NCLOC: 67   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
BookmarksPanel.java - 59.3% 30.8% 50%
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;
 38   
 39    import java.util.ArrayList;
 40   
 41    import javax.swing.*;
 42    import java.awt.event.*;
 43   
 44    import edu.rice.cs.drjava.model.RegionManager;
 45    import edu.rice.cs.drjava.model.RegionManagerListener;
 46    import edu.rice.cs.drjava.model.MovingDocumentRegion;
 47   
 48    /** Panel for displaying bookmarks. Only runs in the event thread.
 49    * @version $Id: BookmarksPanel.java 5236 2010-04-27 01:43:36Z mgricken $
 50    */
 51    public class BookmarksPanel extends RegionsTreePanel<MovingDocumentRegion> {
 52    protected JButton _goToButton;
 53    protected JButton _removeButton;
 54    protected JButton _removeAllButton;
 55   
 56    /** Constructs a new bookmarks panel.
 57    * This is swing view class and hence should only be accessed from the event-handling thread.
 58    * @param frame the MainFrame
 59    */
 60  38 public BookmarksPanel(MainFrame frame, RegionManager<MovingDocumentRegion> bookmarkManager) {
 61  38 super(frame, "Bookmarks", bookmarkManager);
 62  38 _regionManager.addListener(new RegionManagerListener<MovingDocumentRegion>() {
 63  0 public void regionAdded(MovingDocumentRegion r) { addRegion(r); }
 64  0 public void regionChanged(MovingDocumentRegion r) {
 65  0 regionRemoved(r);
 66  0 regionAdded(r);
 67    }
 68  0 public void regionRemoved(MovingDocumentRegion r) { removeRegion(r); }
 69    });
 70    }
 71   
 72    /** Action performed when the Enter key is pressed. Should be overridden. */
 73  0 protected void performDefaultAction() {
 74  0 goToRegion();
 75    }
 76   
 77    /** Creates the buttons for controlling the regions. Should be overridden. */
 78  38 protected JComponent[] makeButtons() {
 79  38 Action goToAction = new AbstractAction("Go to") {
 80  0 public void actionPerformed(ActionEvent ae) {
 81  0 goToRegion();
 82    }
 83    };
 84  38 _goToButton = new JButton(goToAction);
 85   
 86  38 Action removeAction = new AbstractAction("Remove") {
 87  0 public void actionPerformed(ActionEvent ae) { _remove(); } // remove is inherited from RegionsTreePanel
 88    };
 89   
 90  38 _removeButton = new JButton(removeAction);
 91   
 92  38 Action removeAllAction = new AbstractAction("Remove All") {
 93  0 public void actionPerformed(ActionEvent ae) {
 94    // startChanging();
 95  0 _regionManager.clearRegions();
 96    // finishChanging();
 97    }
 98    };
 99  38 _removeAllButton = new JButton(removeAllAction);
 100   
 101  38 JComponent[] buts = new JComponent[] {
 102    _goToButton,
 103    _removeButton,
 104    _removeAllButton
 105    };
 106   
 107  38 return buts;
 108    }
 109   
 110    /** Update button state and text. */
 111  38 protected void _updateButtons() {
 112  38 ArrayList<MovingDocumentRegion> regs = getSelectedRegions();
 113  38 _goToButton.setEnabled(regs.size() == 1);
 114  38 _removeButton.setEnabled(regs.size() > 0);
 115  38 _removeAllButton.setEnabled(_rootNode != null && _rootNode.getDepth() > 0);
 116    }
 117   
 118    /** Makes the popup menu actions. Should be overridden if additional actions besides "Go to" and "Remove" are added. */
 119  38 protected AbstractAction[] makePopupMenuActions() {
 120  38 AbstractAction[] acts = new AbstractAction[] {
 121  0 new AbstractAction("Go to") { public void actionPerformed(ActionEvent e) { goToRegion(); } },
 122   
 123    new AbstractAction("Remove") {
 124  0 public void actionPerformed(ActionEvent e) {
 125  0 for (MovingDocumentRegion r: getSelectedRegions()) _regionManager.removeRegion(r);
 126    }
 127    }
 128    };
 129  38 return acts;
 130    }
 131    }