Coverage Report - org.jtheque.core.managers.view.impl.components.panel.CardPanel
 
Classes in this File Line Coverage Branch Coverage Complexity
CardPanel
0 %
0/13
N/A
1
 
 1  
 package org.jtheque.core.managers.view.impl.components.panel;
 2  
 
 3  
 import javax.swing.JPanel;
 4  
 import java.awt.CardLayout;
 5  
 import java.awt.Component;
 6  
 import java.util.Collection;
 7  
 import java.util.HashMap;
 8  
 import java.util.Map;
 9  
 
 10  
 /*
 11  
  * This file is part of JTheque.
 12  
  *            
 13  
  * JTheque is free software: you can redistribute it and/or modify
 14  
  * it under the terms of the GNU General Public License as published by
 15  
  * the Free Software Foundation, either version 3 of the License. 
 16  
  *
 17  
  * JTheque is distributed in the hope that it will be useful,
 18  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 19  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 20  
  * GNU General Public License for more details.
 21  
  *
 22  
  * You should have received a copy of the GNU General Public License
 23  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 24  
  */
 25  
 
 26  
 /**
 27  
  * A panel with different layers. Only one layer is displayed at the same time.
 28  
  *
 29  
  * @author Baptiste Wicht
 30  
  * @param <T> The type of component to display for layer.
 31  
  */
 32  
 public class CardPanel<T extends Component> extends JPanel {
 33  
     private final CardLayout layout;
 34  
 
 35  
     private T current;
 36  
 
 37  0
     private final Map<String, T> layers = new HashMap<String, T>(5);
 38  
 
 39  
     /**
 40  
      * Construct a new <code>CardPanel</code>.
 41  
      */
 42  
     public CardPanel() {
 43  0
         super();
 44  
 
 45  0
         layout = new CardLayout();
 46  
 
 47  0
         setLayout(layout);
 48  0
     }
 49  
 
 50  
     /**
 51  
      * Add a layer to the panel.
 52  
      *
 53  
      * @param component The component.
 54  
      * @param layer     The layer key.
 55  
      */
 56  
     public void addLayer(T component, String layer) {
 57  0
         layers.put(layer, component);
 58  
 
 59  0
         add(component, layer);
 60  0
     }
 61  
 
 62  
     /**
 63  
      * Return all the layers of the of the panel.
 64  
      *
 65  
      * @return A <code>Collection</code> containing all the layers of the panel.
 66  
      */
 67  
     public Collection<T> getLayers() {
 68  0
         return layers.values();
 69  
     }
 70  
 
 71  
     /**
 72  
      * Return the currently displayed layer.
 73  
      *
 74  
      * @return The current layer.
 75  
      */
 76  
     public T getCurrentLayer() {
 77  0
         return current;
 78  
     }
 79  
 
 80  
     /**
 81  
      * Display the layer.
 82  
      *
 83  
      * @param layer The key of the layer.
 84  
      */
 85  
     public void displayLayer(String layer) {
 86  0
         current = layers.get(layer);
 87  
 
 88  0
         layout.show(this, layer);
 89  0
     }
 90  
 }