SPARK-984, in Preferences -> GroupChat -> Check "Names have random colors"

new entry in locales:
menuitem.add.groupchat.random.colors = Names have &random colors


---
new method in roar to prevent showing messages in groupchats

git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@12458 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Wolf Posdorfer
2011-06-07 15:31:32 +00:00
committed by wolf.posdorfer
parent dbb18e3919
commit 136564549b
8 changed files with 161 additions and 87 deletions

Binary file not shown.

View File

@ -1334,13 +1334,28 @@ public final class GroupChatRoom extends ChatRoom {
return subjectPanel;
}
/**
* Returns the Color to use
* Use Color.blue for yourself
* @param nickname
* @return
*/
public Color getColor(String nickname) {
int index = 0;
for (int i = 0; i < nickname.length(); i++) {
index += nickname.charAt(i) * i;
}
return ChatManager.COLORS[index % ChatManager.COLORS.length];
if (nickname.equals(this.getNickname())) {
return Color.BLUE;
} else {
if (pref.isMucRandomColors()) {
int index = 0;
for (int i = 0; i < nickname.length(); i++) {
index += nickname.charAt(i) * i;
}
return ChatManager.COLORS[index % ChatManager.COLORS.length];
} else {
return Color.red;
}
}
}

View File

@ -75,6 +75,7 @@ public class GroupChatPreference implements Preference {
boolean showjoinleavemessage = localPreferences.isShowJoinLeaveMessagesEnabled();
boolean showroleicons = localPreferences.isShowingRoleIcons();
boolean autoAcceptMucInvite = localPreferences.isAutoAcceptMucInvite();
boolean randomColors = localPreferences.isMucRandomColors();
panel.setMucHighNameEnabled(highlightMyName);
panel.setMucHighTextEnabled(highlightMyText);
@ -82,6 +83,7 @@ public class GroupChatPreference implements Preference {
panel.setShowJoinLeaveMessagesEnabled(showjoinleavemessage);
panel.setShowRoleIconInsteadStatusIcon(showroleicons);
panel.setAutoAcceptMuc(autoAcceptMucInvite);
panel.setRandomColors(randomColors);
}
};
@ -98,6 +100,7 @@ public class GroupChatPreference implements Preference {
pref.setShowJoinLeaveMessagesEnabled(panel.isShowJoinLeaveMessagesEnabled());
pref.setShowRoleIconInsteadStatusIcon(panel.isShowingRoleIcons());
pref.setAutoAcceptMucInvite(panel.isAutoAcceptMuc());
pref.setMucRandomColors(panel.isRandomColors());
SettingsManager.saveSettings();
}

View File

@ -44,7 +44,8 @@ public class GroupChatPreferencePanel extends JPanel {
private JCheckBox showjoinleavemessage = new JCheckBox();
private JCheckBox showroleicons = new JCheckBox();
private JCheckBox _autoAcceptInvites = new JCheckBox();
private JCheckBox _randomcolors = new JCheckBox();
private JPanel gCPanel = new JPanel();
/**
* Constructor invokes UI setup.
@ -63,6 +64,7 @@ public class GroupChatPreferencePanel extends JPanel {
ResourceUtils.resButton(showjoinleavemessage , Res.getString("menuitem.add.groupchat.showjoinleavemessage"));
ResourceUtils.resButton(showroleicons , Res.getString("menuitem.add.groupchat.showrolesinsteadofstatus"));
ResourceUtils.resButton(_autoAcceptInvites , Res.getString("menuitem.add.groupchat.auto.accept.invite"));
ResourceUtils.resButton(_randomcolors , Res.getString("menuitem.add.groupchat.random.colors"));
gCPanel.setBorder(BorderFactory.createTitledBorder(Res.getString("title.group.chat.settings")));
@ -72,10 +74,11 @@ public class GroupChatPreferencePanel extends JPanel {
gCPanel.add(highlightMyName , new GridBagConstraints(0, 0, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
gCPanel.add(highlightMyText , new GridBagConstraints(0, 1, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
gCPanel.add(highlightPopName , new GridBagConstraints(0, 2, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
gCPanel.add(showjoinleavemessage, new GridBagConstraints(0, 3, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
gCPanel.add(showroleicons , new GridBagConstraints(0, 4, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
gCPanel.add(_autoAcceptInvites , new GridBagConstraints(0, 5, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
gCPanel.add(_randomcolors , new GridBagConstraints(0, 2, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
gCPanel.add(highlightPopName , new GridBagConstraints(0, 3, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
gCPanel.add(showjoinleavemessage, new GridBagConstraints(0, 4, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
gCPanel.add(showroleicons , new GridBagConstraints(0, 5, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
gCPanel.add(_autoAcceptInvites , new GridBagConstraints(0, 6, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
}
@ -126,6 +129,14 @@ public class GroupChatPreferencePanel extends JPanel {
public boolean isAutoAcceptMuc() {
return _autoAcceptInvites.isSelected();
}
public void setRandomColors(boolean random) {
_randomcolors.setSelected(random);
}
public boolean isRandomColors() {
return _randomcolors.isSelected();
}
}

View File

@ -744,6 +744,14 @@ public class LocalPreferences {
public boolean isMucHighTextEnabled() {
return getBoolean("isMucHighTextOn", false);
}
public boolean isMucRandomColors(){
return getBoolean("isMucRandomColors", true);
}
public void setMucRandomColors(boolean value){
setBoolean("isMucRandomColors", value);
}
public boolean isMucHighToastEnabled() {
return getBoolean("isMucHighToastOn", false);

View File

@ -19,7 +19,7 @@
*/
package org.jivesoftware.spark.roar;
import java.util.Calendar;
import java.util.HashMap;
import javax.swing.JFrame;
@ -40,6 +40,8 @@ public class RoarMessageListener implements GlobalMessageListener {
private RoarDisplayType _displaytype;
private HashMap<String, Long> _rooms = new HashMap<String, Long>();
public RoarMessageListener() {
_displaytype = RoarProperties.getInstance().getDisplayTypeClass();
@ -56,11 +58,14 @@ public class RoarMessageListener implements GlobalMessageListener {
int framestate = SparkManager.getChatManager().getChatContainer()
.getChatFrame().getState();
boolean isoldgroupchat = isOldGroupchat(message);
// boolean isoldgroupchat = isOldGroupchat(message);
boolean isoldgroupchat = checkTime(room, message);
if (framestate == JFrame.NORMAL && activeroom.equals(room)
&& room.isShowing()
&& (isoldgroupchat || isMessageFromRoom(room, message))) {
&& (isoldgroupchat || isMessageFromRoom(room, message)))
{
// Do Nothing
} else {
_displaytype.messageReceived(room, message);
@ -72,92 +77,122 @@ public class RoarMessageListener implements GlobalMessageListener {
}
/**
* Checks if the Messages come from a time prior entering the groupchat
*
* @param message
* @return true if this is an old Message
*/
private boolean isOldGroupchat(Message message) {
Calendar cal = Calendar.getInstance();
private boolean checkTime(ChatRoom room, Message message) {
int day = cal.get(Calendar.DATE);
int month = cal.get(Calendar.MONTH) + 1;
int year = cal.get(Calendar.YEAR);
boolean result = false;
if (room.getChatType() == Message.Type.groupchat) {
StringBuilder build = new StringBuilder();
// Append leading 0's to hour,minute,seconds
build.append(year);
build.append(month < 10 ? "0" + month : month);
build.append(day < 10 ? "0" + day : day);
int todaysDate = Integer.parseInt(build.toString());
// Append leading 0's to hour,minute,seconds
String hour = cal.get(Calendar.HOUR_OF_DAY) < 10 ? "0"
+ cal.get(Calendar.HOUR_OF_DAY) : ""
+ cal.get(Calendar.HOUR_OF_DAY);
String minute = cal.get(Calendar.MINUTE) < 10 ? "0"
+ cal.get(Calendar.MINUTE) : "" + cal.get(Calendar.MINUTE);
String second = cal.get(Calendar.SECOND) < 10 ? "0"
+ cal.get(Calendar.SECOND) : "" + cal.get(Calendar.SECOND);
int todaysHour = Integer.parseInt(hour + minute + second);
String stamp = "";
// get String with timestamp
// 20110526T08:27:18
if (message.toXML().contains("stamp=")) {
stamp = extractDate(message.toXML());
}
boolean isoldgroupchat = false;
if (stamp.length() > 0) {
// 20110526T08:27:18
// split into 20110526
// and 08:27:18
String[] split = stamp.split("T");
int dateFromMessage = Integer.parseInt(split[0]);
int hourFromMessage = Integer.parseInt(split[1].replace(":", ""));
// if dateFromMessage < todaysDate it is an old Chat
isoldgroupchat = dateFromMessage < todaysDate;
// if is still not old chat
if (!isoldgroupchat) {
// check if the time from Message < time now
isoldgroupchat = hourFromMessage < todaysHour;
if (_rooms.containsKey(room.getRoomname())
&& _rooms.get(room.getRoomname()) == -1L) {
return true;
}
if (!_rooms.containsKey(room.getRoomname())) {
_rooms.put(room.getRoomname(), System.currentTimeMillis());
return true;
} else {
long start = _rooms.get(room.getRoomname());
long now = System.currentTimeMillis();
result = (now - start) < 1500;
if (result) {
_rooms.put(room.getRoomname(), -1L);
}
}
}
return isoldgroupchat;
return result;
}
// /**
// * Checks if the Messages come from a time prior entering the groupchat
// *
// * @param message
// * @return true if this is an old Message
// */
// private boolean isOldGroupchat(Message message) {
// Calendar cal = Calendar.getInstance();
//
// int day = cal.get(Calendar.DATE);
// int month = cal.get(Calendar.MONTH) + 1;
// int year = cal.get(Calendar.YEAR);
//
// StringBuilder build = new StringBuilder();
// // Append leading 0's to hour,minute,seconds
// build.append(year);
// build.append(month < 10 ? "0" + month : month);
// build.append(day < 10 ? "0" + day : day);
//
// int todaysDate = Integer.parseInt(build.toString());
//
// // Append leading 0's to hour,minute,seconds
// String hour = cal.get(Calendar.HOUR_OF_DAY) < 10 ? "0"
// + cal.get(Calendar.HOUR_OF_DAY) : ""
// + cal.get(Calendar.HOUR_OF_DAY);
// String minute = cal.get(Calendar.MINUTE) < 10 ? "0"
// + cal.get(Calendar.MINUTE) : "" + cal.get(Calendar.MINUTE);
// String second = cal.get(Calendar.SECOND) < 10 ? "0"
// + cal.get(Calendar.SECOND) : "" + cal.get(Calendar.SECOND);
//
// int todaysHour = Integer.parseInt(hour + minute + second);
//
// String stamp = "";
//
// // get String with timestamp
// // 20110526T08:27:18
// if (message.toXML().contains("stamp=")) {
// stamp = extractDate(message.toXML());
// }
//
// boolean isoldgroupchat = false;
//
// if (stamp.length() > 0) {
// // 20110526T08:27:18
// // split into 20110526
// // and 08:27:18
// String[] split = stamp.split("T");
// int dateFromMessage = Integer.parseInt(split[0]);
//
// int hourFromMessage = Integer.parseInt(split[1].replace(":", ""));
//
// // if dateFromMessage < todaysDate it is an old Chat
// isoldgroupchat = dateFromMessage < todaysDate;
//
// // if is still not old chat
// if (!isoldgroupchat) {
// // check if the time from Message < time now
// isoldgroupchat = hourFromMessage < todaysHour;
// }
//
// }
// return isoldgroupchat;
// }
@Override
public void messageSent(ChatRoom room, Message message) {
_displaytype.messageSent(room, message);
}
/**
* Extracts the time stamp from a given xmpp packet
*
* @param xmlstring
* @return String like <b>20110526T08:27:18</b>, split at <b>"T"</b>
*/
private String extractDate(String xmlstring) {
int indexofstamp = xmlstring.indexOf("stamp=");
String result = xmlstring
.substring(indexofstamp + 7, indexofstamp + 24)
.replace("-", "");
return result;
}
// /**
// * Extracts the time stamp from a given xmpp packet
// *
// * @param xmlstring
// * @return String like <b>20110526T08:27:18</b>, split at <b>"T"</b>
// */
// private String extractDate(String xmlstring) {
// int indexofstamp = xmlstring.indexOf("stamp=");
// String result = xmlstring
// .substring(indexofstamp + 7, indexofstamp + 24)
// .replace("-", "");
// return result;
//
// }
/**
* Check if the message comes directly from the room
*
* @param room
* @param message
* @return boolean

View File

@ -501,6 +501,7 @@ menuitem.add.groupchat.popname = Show &toast popup when someone says my name
menuitem.add.groupchat.showjoinleavemessage = &Show join and leave messages
menuitem.add.groupchat.showrolesinsteadofstatus = Show chat role icons instead of presence icons
menuitem.add.groupchat.auto.accept.invite = &Automatically accept groupchat invites
menuitem.add.groupchat.random.colors = Names have &random colors
menuitem.always.on.top = Always on top
menuitem.alert.when.online = Alert when user is available
menuitem.ban = Ban

View File

@ -755,9 +755,10 @@ menuitem.user.guide = Benutzerhandbuch
menuitem.add.groupchat.myname = Meinen &Namen hervorheben, wenn ihn jemand schreibt
menuitem.add.groupchat.mytext = Meinen &Text hervorheben, wenn ich etwas schreibe
menuitem.add.groupchat.popname = &Zeige ein Popup, wenn jemand meinen Namen schreibt
menuitem.add.groupchat.showjoinleavemessage = Zeige an wenn jemand den Raum betritt oder verl<72>sst
menuitem.add.groupchat.showrolesinsteadofstatus = Zeige Chatrecht-Icons anstelle von Statusicons
menuitem.add.groupchat.auto.accept.invite = Konferenzeinladungen &automatisch aktzeptieren
menuitem.add.groupchat.showjoinleavemessage = Zeige an wenn jemand den &Raum betritt oder verl<72>sst
menuitem.add.groupchat.showrolesinsteadofstatus = Zeige &Chatrecht-Icons anstelle von Statusicons
menuitem.add.groupchat.auto.accept.invite = &Konferenzeinladungen automatisch aktzeptieren
menuitem.add.groupchat.random.colors = Zeige Namen mit zuf<75>lligen &Farben
menuitem.show.offline.users = Zeige Offline User
menuitem.expand.all.groups = <EFBFBD>ffne alle Gruppen
menuitem.collapse.all.groups = Schlie<EFBFBD>e alle Gruppen