Coverage Report - org.jtheque.core.managers.view.impl.components.MainTabbedPane
 
Classes in this File Line Coverage Branch Coverage Complexity
MainTabbedPane
0 %
0/23
0 %
0/8
2
MainTabbedPane$1
N/A
N/A
2
MainTabbedPane$PositionComparator
0 %
0/2
N/A
2
 
 1  
 package org.jtheque.core.managers.view.impl.components;
 2  
 
 3  
 import org.jtheque.core.managers.Managers;
 4  
 import org.jtheque.core.managers.language.ILanguageManager;
 5  
 import org.jtheque.core.managers.language.TabTitleUpdater;
 6  
 import org.jtheque.core.managers.view.able.IViewManager;
 7  
 import org.jtheque.core.managers.view.able.components.TabComponent;
 8  
 import org.jtheque.core.managers.view.listeners.TabEvent;
 9  
 import org.jtheque.core.managers.view.listeners.TabListener;
 10  
 import org.jtheque.utils.collections.CollectionUtils;
 11  
 
 12  
 import javax.swing.JComponent;
 13  
 import javax.swing.JTabbedPane;
 14  
 import java.io.Serializable;
 15  
 import java.util.Collections;
 16  
 import java.util.Comparator;
 17  
 import java.util.HashMap;
 18  
 import java.util.List;
 19  
 import java.util.Map;
 20  
 
 21  
 /*
 22  
  * This file is part of JTheque.
 23  
  *
 24  
  * JTheque is free software: you can redistribute it and/or modify
 25  
  * it under the terms of the GNU General Public License as published by
 26  
  * the Free Software Foundation, either version 3 of the License.
 27  
  *
 28  
  * JTheque is distributed in the hope that it will be useful,
 29  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 30  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 31  
  * GNU General Public License for more details.
 32  
  *
 33  
  * You should have received a copy of the GNU General Public License
 34  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 35  
  */
 36  
 
 37  
 /**
 38  
  * The main tabbed pane component.
 39  
  *
 40  
  * @author Baptiste Wicht
 41  
  */
 42  
 public final class MainTabbedPane extends LayerTabbedPane implements TabListener {
 43  
     /**
 44  
      * Construct a new MainTabbedPane.
 45  
      */
 46  
     public MainTabbedPane() {
 47  0
         super();
 48  
 
 49  0
         setTabPlacement(JTabbedPane.TOP);
 50  
 
 51  0
         List<TabComponent> components = CollectionUtils.copyOf(Managers.getManager(IViewManager.class).getTabComponents());
 52  0
         Collections.sort(components, new PositionComparator());
 53  
 
 54  0
         Map<JComponent, String> cs = new HashMap<JComponent, String>(components.size());
 55  
 
 56  0
         for (TabComponent component : components) {
 57  0
             addLayeredTab(Managers.getManager(ILanguageManager.class).getMessage(component.getTitleKey()), component.getComponent());
 58  0
             cs.put(component.getComponent(), component.getTitleKey());
 59  
         }
 60  
 
 61  0
         Managers.getManager(IViewManager.class).addTabListener(this);
 62  
 
 63  0
         Managers.getManager(ILanguageManager.class).addInternationalizable(new TabTitleUpdater(this, cs));
 64  0
     }
 65  
 
 66  
     @Override
 67  
     public void tabAdded() {
 68  0
         if (Managers.getManager(IViewManager.class).isTabMainComponent()) {
 69  0
             removeAll();
 70  
 
 71  0
             List<TabComponent> components = CollectionUtils.copyOf(Managers.getManager(IViewManager.class).getTabComponents());
 72  
 
 73  0
             Collections.sort(components, new PositionComparator());
 74  
 
 75  0
             for (TabComponent component : components) {
 76  0
                 addLayeredTab(Managers.getManager(ILanguageManager.class).getMessage(component.getTitleKey()), component.getComponent());
 77  
             }
 78  
 
 79  0
             Managers.getManager(IViewManager.class).refresh(this);
 80  
         }
 81  0
     }
 82  
 
 83  
     @Override
 84  
     public void tabRemoved(TabEvent event) {
 85  0
         if (Managers.getManager(IViewManager.class).isTabMainComponent()) {
 86  0
             removeTabAt(indexOfTab(Managers.getManager(ILanguageManager.class).getMessage(event.getComponent().getTitleKey())));
 87  
 
 88  0
             Managers.getManager(IViewManager.class).refresh(this);
 89  
         }
 90  0
     }
 91  
 
 92  
     /**
 93  
      * A comparator to sort the TabComponent by position.
 94  
      *
 95  
      * @author Baptiste Wicht
 96  
      */
 97  0
     private static final class PositionComparator implements Comparator<TabComponent>, Serializable {
 98  
         @Override
 99  
         public int compare(TabComponent component, TabComponent other) {
 100  0
             return component.getPosition().compareTo(other.getPosition());
 101  
         }
 102  
     }
 103  
 }