1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
42
43
44
45
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 enum Type {
53 Kibitz,
54 Shout,
55 Tell
56 }
57
58
59
60
61 public ChatTabs(ChatPane chatPane) {
62 super();
63 this.chatPane = chatPane;
64 initialize();
65 initTab(Type.Kibitz, "Kibitz");
66 initTab(Type.Shout, "Shout");
67 }
68
69
70
71
72
73
74 private void initialize() {
75 this.setSize(300, 200);
76 addChangeListener(this);
77 }
78
79 public void setBFProperties(BFProperties properties) {
80 this.bfProperties = properties;
81 }
82
83 public void stateChanged(ChangeEvent ce) {
84 this.chatPane.notifyTabChanged();
85 }
86
87 private void initTab(Type type, String name) {
88 ChatOutput co = new ChatOutput();
89
90 this.add(name, co);
91 int i = this.getTabCount();
92 if (type != Type.Kibitz && type != Type.Shout)
93 this.setTabComponentAt(i-1, new ButtonTabComponent(this));
94 }
95
96 private final String verbs[] = {"says", "shouts", "whispers", "kibitzes",
97 "tell", "shout", "whisper", "kibitz"};
98
99 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 if (cookie == FIBS_NobodyHeardYou) {
106 ChatOutput co = getChatOutput(Type.Kibitz, null);
107 co.writeBareMessage(message);
108 return;
109 }
110 int mode = cookie - CLIP_SAYS;
111 Type type = modeToType[mode];
112 ChatOutput co = getChatOutput(type, name);
113 if (mode < 4)
114 co.writeMessageFromPlayer(name, verbs[mode], message);
115 else
116 co.writeMessageFromYou(name, verbs[mode], message);
117 }
118
119
120
121
122
123
124
125 private ChatOutput getChatOutput(Type type, String name) {
126 if (type == Type.Kibitz) {
127 if (bfProperties.isChangeTabOnNewMsg())
128 this.setSelectedIndex(0);
129 return((ChatOutput)this.getComponent(0));
130 }
131 if (type == Type.Shout) {
132 if (bfProperties.isChangeTabOnNewMsg() && !bfProperties.isDontChangeTabOnShout())
133 this.setSelectedIndex(1);
134 return((ChatOutput)this.getComponent(1));
135 }
136
137 int i;
138 i = this.indexOfTab(name);
139 if (i == -1) {
140 initTab(Type.Tell, name);
141 i = this.indexOfTab(name);
142 }
143 if (bfProperties.isChangeTabOnNewMsg())
144 this.setSelectedIndex(i);
145 return((ChatOutput)this.getComponentAt(i));
146 }
147 }