|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| TabbedPanel.java | 50% | 81.5% | 56.2% | 71.1% |
|
||||||||||||||
| 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 javax.swing.*; | |
| 40 | import java.awt.event.*; | |
| 41 | import java.awt.*; | |
| 42 | import java.awt.dnd.*; | |
| 43 | import edu.rice.cs.drjava.DrJavaRoot; | |
| 44 | ||
| 45 | /** Extended by all panels that can dynamically be added or removed from the _tabbedPane in MainFrame. Provides a | |
| 46 | * boolean indicating if the panel is being displayed, and a close button. Attaches an action to the close button | |
| 47 | * which calls the _close method. This method can be overwritten in a subclass if needed. | |
| 48 | * @version $Id: TabbedPanel.java 5443 2011-08-17 04:58:50Z rcartwright $ | |
| 49 | */ | |
| 50 | public abstract class TabbedPanel extends JPanel implements DropTargetListener { | |
| 51 | ||
| 52 | /** indicates whether this tab is displayed in the tabbed pane. */ | |
| 53 | protected volatile boolean _displayed; | |
| 54 | /** button which removes this pane's tab. */ | |
| 55 | protected volatile JButton _closeButton; | |
| 56 | // panel that has _closeButton in the north so it can't be stretched vertically | |
| 57 | protected volatile JPanel _closePanel; | |
| 58 | // the panel that the subclasses of TabbedPanel can use | |
| 59 | protected volatile JPanel _mainPanel; | |
| 60 | // used to be able to reference removeTab | |
| 61 | protected volatile MainFrame _frame; | |
| 62 | // string to be displayed on the tab | |
| 63 | private volatile String _name; | |
| 64 | ||
| 65 | /** Constructor. | |
| 66 | * @param frame MainFrame displaying the tab | |
| 67 | * @param name Name to display for the tab | |
| 68 | */ | |
| 69 | 228 | public TabbedPanel(MainFrame frame, String name) { |
| 70 | 228 | _frame = frame; |
| 71 | 228 | _name = name; |
| 72 | 228 | _setUpPanes(); |
| 73 | 228 | _displayed = false; |
| 74 | } | |
| 75 | ||
| 76 | /** Puts the close panel in the east of this panel and puts the main panel in the | |
| 77 | * center. Also adds the action to the close button. | |
| 78 | */ | |
| 79 | 228 | private void _setUpPanes() { |
| 80 | 228 | this.setFocusCycleRoot(true); |
| 81 | 228 | this.setLayout(new BorderLayout()); |
| 82 | ||
| 83 | 228 | _mainPanel = new JPanel(); |
| 84 | 228 | _closePanel = new JPanel(new BorderLayout()); |
| 85 | 228 | _closeButton = new CommonCloseButton(_closeListener); |
| 86 | 228 | _closePanel.add(_closeButton, BorderLayout.NORTH); |
| 87 | 228 | add(_closePanel, BorderLayout.EAST); |
| 88 | 228 | add(_mainPanel, BorderLayout.CENTER); |
| 89 | } | |
| 90 | ||
| 91 | /** Defines the action that takes place upon clicking the close button. */ | |
| 92 | private final ActionListener _closeListener = new ActionListener() { | |
| 93 | 0 | public void actionPerformed(ActionEvent e) { _close(); } |
| 94 | }; | |
| 95 | ||
| 96 | /** Visibly closes the panel and removes it from the frame. */ | |
| 97 | 12 | protected void _close() { |
| 98 | // System.err.println("TabbedPanel._close() called"); | |
| 99 | 12 | _displayed = false; |
| 100 | 12 | _frame.removeTab(this); |
| 101 | } | |
| 102 | ||
| 103 | 0 | public void addCloseListener(ActionListener l) { _closeButton.addActionListener(l); } |
| 104 | ||
| 105 | 2 | public void setVisible(boolean b) { |
| 106 | 2 | super.setVisible(b); |
| 107 | 2 | if (_frame._mainSplit.getDividerLocation() > _frame._mainSplit.getMaximumDividerLocation()) |
| 108 | 0 | _frame._mainSplit.resetToPreferredSizes(); |
| 109 | } | |
| 110 | ||
| 111 | /** @return whether this tabbedPanel is displayed in a tab */ | |
| 112 | 60 | public boolean isDisplayed() { return _displayed; } |
| 113 | ||
| 114 | /** @return the display name of this tab. */ | |
| 115 | 1 | public String getName() { return _name; } |
| 116 | ||
| 117 | /** Sets whether the tab is displayed. Doesn't actually show or hide the tab. */ | |
| 118 | 15 | public void setDisplayed(boolean displayed) { _displayed = displayed; } |
| 119 | ||
| 120 | 190 | JPanel getMainPanel() { return _mainPanel; } |
| 121 | ||
| 122 | /** This is overridden so that when switch previous pane focus is called | |
| 123 | * on the currentDefPane, the caret will move here on the first call. | |
| 124 | */ | |
| 125 | 1 | public boolean requestFocusInWindow() { |
| 126 | // System.err.println("requestFocusInWindow called on TabbedPanel"); | |
| 127 | 1 | super.requestFocusInWindow(); |
| 128 | 1 | return _mainPanel.requestFocusInWindow(); |
| 129 | } | |
| 130 | ||
| 131 | /** Drag and drop target. */ | |
| 132 | volatile DropTarget dropTarget = new DropTarget(this, this); | |
| 133 | ||
| 134 | /** User dragged something into the component. */ | |
| 135 | 0 | public void dragEnter(DropTargetDragEvent dropTargetDragEvent) { |
| 136 | 0 | DrJavaRoot.dragEnter(dropTargetDragEvent); |
| 137 | } | |
| 138 | ||
| 139 | 0 | public void dragExit(DropTargetEvent dropTargetEvent) { } |
| 140 | 0 | public void dragOver(DropTargetDragEvent dropTargetDragEvent) { } |
| 141 | 0 | public void dropActionChanged(DropTargetDragEvent dropTargetDragEvent){ } |
| 142 | ||
| 143 | /** User dropped something on the component. Only runs in event thread. */ | |
| 144 | 0 | public /* synchronized */ void drop(DropTargetDropEvent dropTargetDropEvent) { |
| 145 | 0 | DrJavaRoot.drop(dropTargetDropEvent); |
| 146 | } | |
| 147 | } |
|
||||||||||