Coverage Report - org.xmlhammer.gui.util.SelectionPage
 
Classes in this File Line Coverage Branch Coverage Complexity
SelectionPage
97% 
100% 
0
 
 1  
 /*
 2  
  * $Id: SelectionPage.java,v 1.10 2008/05/19 20:41:08 edankert Exp $
 3  
  *
 4  
  * The contents of this file are subject to the Mozilla Public License 
 5  
  * Version 1.1 (the "License"); you may not use this file except in 
 6  
  * compliance with the License. You may obtain a copy of the License at 
 7  
  * http://www.mozilla.org/MPL/ 
 8  
  *
 9  
  * Software distributed under the License is distributed on an "AS IS" basis, 
 10  
  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
 11  
  * for the specific language governing rights and limitations under the License.
 12  
  *
 13  
  * The Original Code is XML Hammer code. (org.xmlhammer.*)
 14  
  *
 15  
  * The Initial Developer of the Original Code is Edwin Dankert. Portions created 
 16  
  * by the Initial Developer are Copyright (C) 2005 - 2006 the Initial Developer. 
 17  
  * All Rights Reserved.
 18  
  *
 19  
  * Contributor(s): Edwin Dankert <edankert@gmail.com>
 20  
  */
 21  
 
 22  
 package org.xmlhammer.gui.util;
 23  
 
 24  
 import java.awt.BorderLayout;
 25  
 import java.awt.event.ItemEvent;
 26  
 import java.awt.event.ItemListener;
 27  
 import java.util.Enumeration;
 28  
 import java.util.Hashtable;
 29  
 
 30  
 import javax.swing.JComboBox;
 31  
 import javax.swing.JPanel;
 32  
 
 33  
 import org.apache.log4j.Logger;
 34  
 import org.xmlhammer.gui.Page;
 35  
 import org.xmlhammer.gui.ProjectView;
 36  
 import org.xmlhammer.gui.actions.PagePropertiesAction;
 37  
 
 38  
 /**
 39  
  * Input Panel.
 40  
  * 
 41  
  * Allows to select either one URI, multiple URIs or 
 42  
  * a range of files.
 43  
  * 
 44  
  * @version $Revision: 1.10 $, $Date: 2008/05/19 20:41:08 $
 45  
  * @author Edwin Dankert <edankert@gmail.com>
 46  
  */
 47  
 
 48  
 public abstract class SelectionPage extends Page implements ItemListener {
 49  
         private static final long serialVersionUID = 3257852090755134776L;
 50  
 
 51  1056
         private Hashtable<String,JPanel> panels = null;
 52  1056
         protected JComboBox selector = null;
 53  1056
         private JPanel centerPanel = null;
 54  
 
 55  
         /**
 56  
          * Constructs a new Input Panel.
 57  
          */
 58  
         public SelectionPage(ProjectView view, String label, boolean properties) {
 59  1056
                 super(view);
 60  1056
                 panels = new Hashtable<String,JPanel>();
 61  
                 
 62  1056
                 selector = new JComboBox();
 63  1056
                 selector.addItemListener( this);
 64  1056
         selector.addItemListener(new UndoableComboBoxItemListener(this, selector));
 65  1056
         getProjectView().getFieldManager().addField(selector);
 66  
                 
 67  1056
                 centerPanel = new JPanel( new BorderLayout());
 68  
 //                centerPanel.setBorder( new EmptyBorder( 2, 2, 0, 0));
 69  1056
         TitleBar bar = new TitleBar(label, selector);
 70  1056
         if (properties) {
 71  484
             bar.add(new PagePropertiesAction(this));
 72  
         }
 73  
 
 74  1056
                 setTitleBar( bar);
 75  1056
                 setCenterPanel( centerPanel);
 76  1056
         }
 77  
         
 78  
         public JPanel getSelectedPanel() { 
 79  116615
                 return panels.get(selector.getSelectedItem());
 80  
         }
 81  
         
 82  
         public void setSelectedPanel(JPanel panel) { 
 83  1056
                 Enumeration<String> e = panels.keys();
 84  
                 
 85  4136
                 while(e.hasMoreElements()) {
 86  3080
                         String key = e.nextElement();
 87  3080
                         if (panels.get(key) == panel) {
 88  1056
                                 selector.setSelectedItem(key);
 89  
                         }
 90  3080
                 }
 91  1056
         }
 92  
 
 93  
         public void addPanel(String name, JPanel panel) {
 94  3080
         Logger.getLogger(this.getClass()).debug("addPanel("+name+", "+panel+")");
 95  3080
                 panels.put(name, panel);
 96  
                 
 97  3080
                 selector.addItem(name);
 98  
                 
 99  3080
                 if (selector.getSelectedIndex() != 0) {
 100  0
                         selector.setSelectedIndex( 0);
 101  
                 }
 102  3080
         }
 103  
         
 104  
     public void itemStateChanged(ItemEvent e) {
 105  2112
         centerPanel.removeAll();
 106  2112
         centerPanel.add(panels.get( selector.getSelectedItem()), BorderLayout.CENTER);
 107  2112
         centerPanel.revalidate();
 108  2112
         centerPanel.repaint();
 109  2112
     }
 110  
 }