Coverage Report - com.buckosoft.fibs.BuckoFIBS.gui.chatWindow.ChatTabs
 
Classes in this File Line Coverage Branch Coverage Complexity
ChatTabs
0%
0/47
0%
0/22
3
ChatTabs$Type
0%
0/4
N/A
3
 
 1  
 /******************************************************************************
 2  
  * ChatTabs.java - Manage the tabs in the chat system.
 3  
  * $Id$
 4  
  * 
 5  
  * BuckoFIBS - Backgammon by BuckoSoft
 6  
  * Copyright(c) 2011 - Dick Balaska - BuckoSoft, Corp.
 7  
  * 
 8  
  * $Log$
 9  
  * Revision 1.1  2011/06/22 06:01:43  dick
 10  
  * Manage the tabs in the chat system.
 11  
  *
 12  
  */
 13  
 
 14  
 /* 
 15  
  * This program is free software: you can redistribute it and/or modify
 16  
  * it under the terms of the GNU General Public License as published by
 17  
  * the Free Software Foundation, either version 3 of the License, or
 18  
  * (at your option) any later version.
 19  
  *
 20  
  * This program is distributed in the hope that it will be useful,
 21  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 22  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 23  
  * GNU General Public License for more details.
 24  
  *
 25  
  * You should have received a copy of the GNU General Public License
 26  
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 27  
  *
 28  
  * The Original Code is BuckoFIBS, <http://www.buckosoft.com/BuckoFIBS/>.
 29  
  * The Initial Developer of the Original Code is Dick Balaska and BuckoSoft, Corp.
 30  
  * 
 31  
  */
 32  
 package com.buckosoft.fibs.BuckoFIBS.gui.chatWindow;
 33  
 
 34  
 import javax.swing.JTabbedPane;
 35  
 import javax.swing.event.ChangeEvent;
 36  
 import javax.swing.event.ChangeListener;
 37  
 
 38  
 import com.buckosoft.fibs.BuckoFIBS.BFProperties;
 39  
 import com.buckosoft.fibs.net.FIBSMessages;
 40  
 
 41  
 /** Manage the tabs in the chat system.
 42  
  * @author Dick Balaska
 43  
  * @since 2011/06/21
 44  
  * @version $Revision$ <br> $Date$
 45  
  * @see <a href="http://cvs.buckosoft.com/Projects/BuckoFIBS/BuckoFIBS/src/main/java/com/buckosoft/fibs/BuckoFIBS/gui/chatWindow/ChatTabs.java">cvs ChatTabs.java</a>
 46  
  */
 47  
 public class ChatTabs extends JTabbedPane implements FIBSMessages, ChangeListener {
 48  
         private static final long serialVersionUID = 1L;
 49  
         private        BFProperties        bfProperties;
 50  
         private        ChatPane                chatPane;
 51  
 
 52  0
         enum Type {
 53  0
                 Kibitz,
 54  0
                 Shout,
 55  0
                 Tell
 56  
         }
 57  
 
 58  
         /**
 59  
          * 
 60  
          */
 61  
         public ChatTabs(ChatPane chatPane) {
 62  0
                 super();
 63  0
                 this.chatPane = chatPane;
 64  0
                 initialize();
 65  0
                 initTab(Type.Kibitz, "Kibitz");
 66  0
                 initTab(Type.Shout, "Shout");
 67  0
         }
 68  
 
 69  
         /**
 70  
          * This method initializes this
 71  
          * 
 72  
          * @return void
 73  
          */
 74  
         private void initialize() {
 75  0
                 this.setSize(300, 200);
 76  0
                 addChangeListener(this);
 77  0
         }
 78  
 
 79  
         public void setBFProperties(BFProperties properties) {
 80  0
                 this.bfProperties = properties;
 81  0
         }
 82  
         
 83  
         public void stateChanged(ChangeEvent ce) {
 84  0
                 this.chatPane.notifyTabChanged();
 85  0
         }
 86  
 
 87  
         private void initTab(Type type, String name) {
 88  0
                 ChatOutput co = new ChatOutput();
 89  
                 //ButtonTabComponent btc = new ButtonTabComponent(this);
 90  0
                 this.add(name, co);
 91  0
                 int i = this.getTabCount();
 92  0
                 if (type != Type.Kibitz && type != Type.Shout)        // Can't delete kibitz and shout
 93  0
                         this.setTabComponentAt(i-1, new ButtonTabComponent(this));
 94  0
         }
 95  
 
 96  0
         private final String verbs[]  = {"says", "shouts", "whispers", "kibitzes",
 97  
                                                                         "tell",  "shout",  "whisper",  "kibitz"};
 98  
 
 99  0
         private        Type modeToType[] = {
 100  
                         Type.Tell, Type.Shout, Type.Kibitz, Type.Kibitz, 
 101  
                         Type.Tell, Type.Shout, Type.Kibitz, Type.Kibitz 
 102  
         };
 103  
 
 104  
         protected void addChatMessage(String name, int cookie, String message) {
 105  0
                 if (cookie == FIBS_NobodyHeardYou) {
 106  0
                         ChatOutput co = getChatOutput(Type.Kibitz, null);
 107  0
                         co.writeBareMessage(message);
 108  0
                         return;
 109  
                 }
 110  0
                 int mode =  cookie - CLIP_SAYS;
 111  0
                 Type type = modeToType[mode];
 112  0
                 ChatOutput co = getChatOutput(type, name);
 113  0
                 if (mode < 4)
 114  0
                         co.writeMessageFromPlayer(name, verbs[mode], message);
 115  
                 else
 116  0
                         co.writeMessageFromYou(name, verbs[mode], message);
 117  0
         }
 118  
 
 119  
         /** Get the requested ChatOutput pane.
 120  
          * If it is a Tell, and it doesn't exist, create it.
 121  
          * @param type
 122  
          * @param name
 123  
          * @return
 124  
          */
 125  
         private ChatOutput getChatOutput(Type type, String name) {
 126  0
                 if (type == Type.Kibitz) {
 127  0
                         if (bfProperties.isChangeTabOnNewMsg())
 128  0
                                 this.setSelectedIndex(0);
 129  0
                         return((ChatOutput)this.getComponent(0));
 130  
                 }
 131  0
                 if (type == Type.Shout) {
 132  0
                         if (bfProperties.isChangeTabOnNewMsg() && !bfProperties.isDontChangeTabOnShout())
 133  0
                                 this.setSelectedIndex(1);
 134  0
                         return((ChatOutput)this.getComponent(1));
 135  
                 }
 136  
 
 137  
                 int i;
 138  0
                 i = this.indexOfTab(name);
 139  0
                 if (i == -1) {
 140  0
                         initTab(Type.Tell, name);
 141  0
                         i = this.indexOfTab(name);
 142  
                 }
 143  0
                 if (bfProperties.isChangeTabOnNewMsg())
 144  0
                         this.setSelectedIndex(i);
 145  0
                 return((ChatOutput)this.getComponentAt(i));
 146  
         }
 147  
 }