Permalink
Browse files

add speech function for Mac OS X

  • Loading branch information...
1 parent 3664b18 commit 93da9fe20fbe2b24b2f63d2b004fd0e51094c699 @yuuakron committed Feb 24, 2012
Showing with 210 additions and 143 deletions.
  1. +101 −143 src/pt/jkaiui/manager/ChatManager.java
  2. +94 −0 src/pt/jkaiui/ui/tools/CommandExecuter.java
  3. +15 −0 src/pt/jkaiui/ui/tools/Say.java
View
244 src/pt/jkaiui/manager/ChatManager.java
@@ -5,44 +5,29 @@
*/
package pt.jkaiui.manager;
+import java.awt.Component;
+import java.io.File;
+import java.net.URL;
import java.text.DateFormat;
-import java.util.logging.Logger;
-import javax.sound.sampled.AudioFormat;
-import javax.sound.sampled.AudioInputStream;
-import javax.sound.sampled.AudioSystem;
-import javax.sound.sampled.Clip;
-import javax.sound.sampled.DataLine;
-import javax.swing.ImageIcon;
-import javax.swing.JTabbedPane;
import java.util.*;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import java.net.URL;
-import java.io.File;
+import javax.sound.sampled.*;
import javax.swing.AbstractListModel;
-
+import javax.swing.ImageIcon;
+import javax.swing.JTabbedPane;
import pt.jkaiui.JKaiUI;
-import pt.jkaiui.core.ChatMessage;
-import pt.jkaiui.core.InMessage;
-import pt.jkaiui.core.KaiString;
-import pt.jkaiui.core.OutMessage;
-import pt.jkaiui.core.User;
-import pt.jkaiui.core.Arena;
-import pt.jkaiui.core.messages.ArenaPMOut;
-import pt.jkaiui.core.messages.ChatOut;
-import pt.jkaiui.core.messages.PMOut;
-import pt.jkaiui.core.messages.ContactOnline;
-import pt.jkaiui.core.messages.ContactOffline;
+import pt.jkaiui.core.KaiConfig.ConfigTag;
+import static pt.jkaiui.core.KaiConfig.ConfigTag.*;
+import pt.jkaiui.core.*;
+import pt.jkaiui.core.messages.*;
import pt.jkaiui.tools.log.ConfigLog;
import pt.jkaiui.ui.ChatPanel;
-import pt.jkaiui.ui.modes.MessengerModeListModel;
-import pt.jkaiui.core.Diags;
-import pt.jkaiui.core.messages.KaiVectorOut;
-import static pt.jkaiui.core.KaiConfig.ConfigTag.*;
-import pt.jkaiui.core.KaiConfig.ConfigTag;
-import pt.jkaiui.core.messages.CreateVectorOut;
import pt.jkaiui.ui.KaiSettingsPanel;
-import java.awt.Component;
+import pt.jkaiui.ui.modes.MessengerModeListModel;
+import pt.jkaiui.ui.tools.Say;
/**
*
@@ -209,18 +194,18 @@ private void processInMessage(InMessage msg) {
// get general arena
panel = (ChatPanel) chatsTable.get(GENERAL_CHAT);
- //チャットで音を鳴らす
+ //チャットで音を鳴らす
if (JKaiUI.getConfig().getConfigBoolean(PLAYMESSAGESOUND) && !msg.getUser().getUser().equalsIgnoreCase("kai orbital mesh")
&& (JKaiUI.getConfig().getConfigBoolean(ChatSound))) {
playMessageSound(SoundKinds.Chat);
}
- //フレンドの発言時に音をならすように変更
+ //フレンドの発言時に音をならすように変更
if (JKaiUI.getConfig().getConfigBoolean(PLAYMESSAGESOUND)
&& (JKaiUI.getConfig().getConfigBoolean(FriendChatSound))
&& (userIsFriend(msg.getUser()))) {
playMessageSound(SoundKinds.FriendChat);
}
- //モデの発言時に音をならすように変更
+ //モデの発言時に音をならすように変更
if (JKaiUI.getConfig().getConfigBoolean(PLAYMESSAGESOUND)
&& (JKaiUI.getConfig().getConfigBoolean(ModeratorChatSound))
&& (msg.getUser().isModerator())) {
@@ -231,21 +216,21 @@ private void processInMessage(InMessage msg) {
panel = getOrCreatePanel(msg.getUser().getUser());
- //PMがきたとき音をならすように変更
+ //PMがきたとき音をならすように変更
if (JKaiUI.getConfig().getConfigBoolean(PLAYMESSAGESOUND)
&& (JKaiUI.getConfig().getConfigBoolean(FriendPMSound))
&& (userIsFriend(msg.getUser()))) {
playMessageSound(SoundKinds.FriendPM);
}
- //ArenaPMがきたとき音をならすように変更
+ //ArenaPMがきたとき音をならすように変更
if (JKaiUI.getConfig().getConfigBoolean(PLAYMESSAGESOUND)
&& (JKaiUI.getConfig().getConfigBoolean(ArenaPMSound))
&& (!userIsFriend(msg.getUser()))) {
playMessageSound(SoundKinds.ArenaPM);
}
/*
- //受信の場合はいつでも機能on
- //PM受信の場合
+ //受信の場合はいつでも機能on
+ //PM受信の場合
try {
msg.setMessage(HtmlUnicodedecode(msg.getMessage(), 10));
} catch (Exception e) {
@@ -262,6 +247,7 @@ private void processInMessage(InMessage msg) {
panel.write(formatInMessage(msg));
// panel.write(msg.getMessage());
+ Say.speakString(msg.getMessage());
// Notify if not selected
enableIconIfSelected(panel);
@@ -286,7 +272,7 @@ private void processOutMessage(OutMessage msg) {
msg.setMessage(texttmp);
}
- //チャット送信時に音を鳴らす
+ //チャット送信時に音を鳴らす
if (JKaiUI.getConfig().getConfigBoolean(PLAYMESSAGESOUND)
&& (JKaiUI.getConfig().getConfigBoolean(SendSound))) {
playMessageSound(SoundKinds.Send);
@@ -302,7 +288,7 @@ private void processOutMessage(OutMessage msg) {
ChatOut chat = new ChatOut();
chat.setMessage(new KaiString(msg.getMessage()));
- JKaiUI.getManager().getExecuter().execute(chat);
+ ActionExecuter.execute(chat);
} else if (msg.getType() == ChatMessage.PRIVATE_MESSAGE) {
@@ -313,7 +299,7 @@ private void processOutMessage(OutMessage msg) {
/*
if (JKaiUI.getConfig().isHtmlUnicode()) {
try {
- //PMの場合、HTMLエンコードをする
+ //PMの場合、HTMLエンコードをする
msg.setMessage(HtmlUnicodeencode(msg.getMessage(), 10));
} catch (Exception e) {
System.out.println("processOutMessage:"+e);
@@ -327,19 +313,19 @@ private void processOutMessage(OutMessage msg) {
arenaPmOut.setUser(new KaiString(msg.getUser().getUser()));
arenaPmOut.setMessage(new KaiString(msg.getMessage()));
- JKaiUI.getManager().getExecuter().execute(arenaPmOut);
+ ActionExecuter.execute(arenaPmOut);
} else {
// PM
pmOut.setUser(new KaiString(msg.getUser().getUser()));
pmOut.setMessage(new KaiString(msg.getMessage()));
- JKaiUI.getManager().getExecuter().execute(pmOut);
+ ActionExecuter.execute(pmOut);
}
/*
if (JKaiUI.getConfig().isHtmlUnicode()) {
try {
- //PMの場合、HTMLデコードをする
+ //PMの場合、HTMLデコードをする
msg.setMessage(HtmlUnicodedecode(msg.getMessage(), 10));
} catch (Exception e) {
System.out.println("processOutMessage:" + e);
@@ -355,6 +341,7 @@ private void processOutMessage(OutMessage msg) {
}
panel.write(formatOutMessage(msg));
+ Say.speakString(msg.getMessage());
}
private String formatOutMessage(OutMessage msg) {
@@ -378,7 +365,7 @@ private String formatMessage(String user, String color, String msg) {
msgtmp = matcher.replaceAll("<a href=\"$0\">$0</a>");
/*
- //html解析 問題あり
+ //html解析 問題あり
Pattern p = Pattern.compile("(http|https):([^\\x00-\\x20()\"<>\\x7F-\\xFF])*", Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(msgtmp);
@@ -387,21 +374,21 @@ private String formatMessage(String user, String color, String msg) {
// System.out.println(m.group());
String tmp = m.group();
String tmp2 = m.group().replaceAll("\\?", "\\\\?");
- msgtmp = msgtmp.replaceFirst(tmp2, "<a href=\"" + tmp + "\">" + tmp + "</a>");//あとから同じドメインのアドレスが出てきた場合にうまくいかない
+ msgtmp = msgtmp.replaceFirst(tmp2, "<a href=\"" + tmp + "\">" + tmp + "</a>");//あとから同じドメインのアドレスが出てきた場合にうまくいかない
}
// System.out.println(msgtmp);
*
*/
- //userにリンクを追加 リンクをクリックするとチャット入力画面に出せる
- //https://sites.google.com/site/yuuakron/dummy/はダミーアドレス
- user = "<a href=\"https://sites.google.com/site/yuuakron/dummy/" + user + "\">" + user + "</a>";
+ //userにリンクを追加 リンクをクリックするとチャット入力画面に出せる
+ //https://sites.google.com/site/yuuakron/dummy/はダミーアドレス
+ String userstr = "<a href=\"https://sites.google.com/site/yuuakron/dummy/" + user + "\">" + user + "</a>";
String out = "";
switch (JKaiUI.getConfig().getConfigInt(ChatDisplayStyle)) {
case 0:
//JKaiUI
- out = "<table style=\"padding:2px;width:100%;font-family:Dialog;" + wordbreak + "font-size:" + JKaiUI.getConfig().getConfigInt(ChatFontSize) + "px\"><tr style=\"background-color:" + color + "\"><td>" + user + "</td><td align=\"right\">";
+ out = "<table style=\"padding:2px;width:100%;font-family:Dialog;" + wordbreak + "font-size:" + JKaiUI.getConfig().getConfigInt(ChatFontSize) + "px\"><tr style=\"background-color:" + color + "\"><td>" + userstr + "</td><td align=\"right\">";
if (JKaiUI.getConfig().getConfigBoolean(SHOWTIMESTAMPS)) {
Date dat = new Date();
String stime = DateFormat.getTimeInstance().format(dat);
@@ -410,25 +397,25 @@ private String formatMessage(String user, String color, String msg) {
out += "</td></tr><tr><td colspan=2>" + msgtmp + "</td></tr></table>";
break;
case 2:
- //WebUI風
+ //WebUI風
out = "<table style=\"width:100%;font-family:Dialog;" + wordbreak + "font-size:" + JKaiUI.getConfig().getConfigInt(ChatFontSize) + "px\"><tr>";
if (JKaiUI.getConfig().getConfigBoolean(SHOWTIMESTAMPS)) {
Date dat = new Date();
String stime = DateFormat.getTimeInstance().format(dat);
out += "<td style=\"background-color:" + color + ";width:" + (JKaiUI.getConfig().getConfigInt(ChatFontSize) * 7) + "\">" + stime + " </td>";
}
- out += "<td style=\"background-color:" + color + ";width:" + (JKaiUI.getConfig().getConfigInt(ChatFontSize) * 14) + "\">" + user + "</td>";
+ out += "<td style=\"background-color:" + color + ";width:" + (JKaiUI.getConfig().getConfigInt(ChatFontSize) * 14) + "\">" + userstr + "</td>";
out += "<td>" + msgtmp + "</td></tr></table>";
break;
case 1:
- //GUI風
+ //GUI風
out = "<span style=\"font-family:Dialog;background-color:" + color + ";font-size:" + JKaiUI.getConfig().getConfigInt(ChatFontSize) + "px\">";
if (JKaiUI.getConfig().getConfigBoolean(SHOWTIMESTAMPS)) {
Date dat = new Date();
String stime = DateFormat.getTimeInstance().format(dat);
out += stime + " ";
}
- out += user + "</span>";
+ out += userstr + "</span>";
out += "<span style=\"font-family:Dialog;" + wordbreak + "font-size:" + JKaiUI.getConfig().getConfigInt(ChatFontSize) + "px\"> : " + msgtmp + "</span>";
break;
default:
@@ -444,12 +431,12 @@ private void initEmotIcon() {
EmotIcons = new ArrayList();
ArrayList tmp = new ArrayList(70);
- _logger.severe("url icon:"+url);
+ _logger.log(Level.SEVERE, "url icon:{0}", url);
String settingfolder = JKaiUI.getConfig().getConfigSettingFolder() +"/";
- //WebUIから抽出
+ //WebUIから抽出
tmp.add(":arrr:,file:"+settingfolder+"emoticons/arrr.gif");
tmp.add(":awe:,file:"+settingfolder+"emoticons/awe.gif");
tmp.add(":blink:,file:"+settingfolder+"emoticons/blink.gif");
@@ -503,7 +490,7 @@ private void initEmotIcon() {
}
}
- //JKaiUI original オリジナルは最後に処理する必要あり
+ //JKaiUI original オリジナルは最後に処理する必要あり
EmotIcons.add(":)," + url + "/pt/jkaiui/ui/resources/emoticons/smile.png");
EmotIcons.add(":(," + url + "/pt/jkaiui/ui/resources/emoticons/sad.png");
EmotIcons.add(":*," + url + "/pt/jkaiui/ui/resources/emoticons/kiss.png");
@@ -551,37 +538,41 @@ private boolean checkEmotIconFile(String emoticonstring) {
private String encodeMessage(String s) {
- s = s.replace("&", "&amp;");
- s = s.replace(">", "&gt;");
- s = s.replace("<", "&lt;");
+ String str=s;
+
+ str = str.replace("&", "&amp;");
+ str = str.replace(">", "&gt;");
+ str = str.replace("<", "&lt;");
//s = s.replace(":)","<img src=\"jar:file:/home/pedro/tex/kai/jkaiui/dist/jKaiUI.jar!/pt/jkaiui/ui/resources/emoticons/smile.png\">");
- s = encodeEmotIcon(s);
+ str = encodeEmotIcon(str);
// System.out.println(s);
- return s;
+ return str;
}
private String encodeEmotIcon(String s) {
+ String str = s;
+
for (int i = 0; i < EmotIcons.size(); i++) {
String[] tmp = ((String) EmotIcons.get(i)).split(",");
// System.out.println(tmp[0] + ":" + tmp[1]);
- s = s.replace(tmp[0], encodeImgTag(tmp[1]));
+ str = str.replace(tmp[0], encodeImgTag(tmp[1]));
}
- return s;
+ return str;
}
private String encodeImgTag(String s) {
- s = "<img src=\"" + s + "\">";
+ String tmp = "<img src=\"" + s + "\">";
- return s;
+ return tmp;
}
private String getColor(String s) {
@@ -609,11 +600,11 @@ private String getColor(String s) {
private ChatPanel getOrCreatePanel(String name) {
- ChatPanel panel = null;
+ ChatPanel panel;
if (chatsTable.get(name) == null) {
- //PMパネルを開いた場合に音を鳴らすように変更
+ //PMパネルを開いた場合に音を鳴らすように変更
if (JKaiUI.getConfig().getConfigBoolean(PLAYMESSAGESOUND)
&& (JKaiUI.getConfig().getConfigBoolean(PMOpenSound))) {
playMessageSound(SoundKinds.PMOpen);
@@ -629,7 +620,7 @@ private ChatPanel getOrCreatePanel(String name) {
} else if (((ChatPanel)chatsTable.get(name)).containMainUI()) {
panel = (ChatPanel) chatsTable.get(name);
} else {
- //PMパネルを開いた場合に音を鳴らすように変更
+ //PMパネルを開いた場合に音を鳴らすように変更
if (JKaiUI.getConfig().getConfigBoolean(PLAYMESSAGESOUND)
&& (JKaiUI.getConfig().getConfigBoolean(PMOpenSound))) {
playMessageSound(SoundKinds.PMOpen);
@@ -736,25 +727,6 @@ public void playMessageSound(SoundKinds sound) {
}
public void loginFriend(ContactOnline friend) {
-/*
- MessengerModeListModel listmodel = (MessengerModeListModel) JKaiUI.getMessengerMode().getListModel();
-
- //最初は表示、2回目以降はエスタ状態なら表示しない
- for (int i = 0; i < listmodel.size(); i++) {
- Object obj = listmodel.getElementAt(i);
- if (obj instanceof User) {
- User user = (User) obj;
- if (user.getName().equals(friend.getUser().decode())) {
- System.out.println(user.getPing());
- if (user.getPing() == 0) {
- user.setPing(-1);
- }else if(user.getPing() < 0){
- return;
- }
- }
- }
- }
-*/
// Notify that user has entered the arena
Object[] panels = chatsTable.values().toArray();
// ChatPanel panel = (ChatPanel) chatsTable.get(GENERAL_CHAT);
@@ -763,7 +735,7 @@ public void loginFriend(ContactOnline friend) {
panel.write("<div style=\"color:black; font-size:" + JKaiUI.getConfig().getConfigInt(SystemFontSize) + "px;\"> -- " + friend.getUser().decode() + " is logged in" + "</div>");
}
- //フレンドのログイン時に音を鳴らす
+ //フレンドのログイン時に音を鳴らす
if (JKaiUI.getConfig().getConfigBoolean(PLAYMESSAGESOUND)
&& (JKaiUI.getConfig().getConfigBoolean(FriendOnlineSound))) {
playMessageSound(ChatManager.SoundKinds.FriendOnline);
@@ -776,26 +748,7 @@ public void logoutFriend(ContactOffline friend) {
// ChatPanel panel = (ChatPanel) chatsTable.get(GENERAL_CHAT);
// panel.write("<div style=\"color:black; font-size:" + JKaiUI.getConfig().getConfigInt(SystemFontSize) + "px;\"> -- " + friend.getUser().decode() + " is logged out" + "</div>");
-
-/*
- MessengerModeListModel listmodel = (MessengerModeListModel) JKaiUI.getMessengerMode().getListModel();
-
- //最初は表示、2回目以降はエスタ状態なら表示しない
- for (int i = 0; i < listmodel.size(); i++) {
- Object obj = listmodel.getElementAt(i);
- if (obj instanceof User) {
- User user = (User) obj;
- if(user.getName().equals(friend.getUser().decode())){
- System.out.println(user.getPing());
- if (user.getPing() == 0) {
- user.setPing(-1);
- }else if(user.getPing() < 0){
- return;
- }
- }
- }
- }
-*/
+
Object[] panels = chatsTable.values().toArray();
// ChatPanel panel = (ChatPanel) chatsTable.get(GENERAL_CHAT);
for(int i=0;i < panels.length;i++){
@@ -849,7 +802,7 @@ public synchronized String previouschathistory() {
if (chathistory.size() > 0) {
if (0 <= chathistoryindex && chathistory.size() > chathistoryindex) {
chathistoryindex--;
- return (String) chathistory.get(chathistoryindex + 1);//現在値を送信
+ return (String) chathistory.get(chathistoryindex + 1);//現在値を送信
}else if(chathistory.size() == chathistoryindex){
chathistoryindex--;
}else {
@@ -868,12 +821,12 @@ private String JKaiUIcommand(String text) {
if (tmp[0].matches("^%(.*)")) {
//System.out.println(m.group(1));
if (tmp[0].equalsIgnoreCase("%send")) {
- //コマンドの送信
+ //コマンドの送信
return JKaiUICommands(text.replaceFirst("%send\\s+", ""));
}else if(tmp[0].equalsIgnoreCase("%ask")){
return text;
}else {
- //コマンドを表示
+ //コマンドを表示
// ChatPanel panel = (ChatPanel) chatsTable.get(GENERAL_CHAT);
ChatPanel panel = (ChatPanel)JKaiUI.getMainUI().jTabbedPane.getSelectedComponent();
@@ -885,7 +838,7 @@ private String JKaiUIcommand(String text) {
return null;
}
}
- //通常のテキスト
+ //通常のテキスト
return text;
}
@@ -898,7 +851,7 @@ private String JKaiUIAskcommand(InMessage msg) {
ChatPanel panel = (ChatPanel)JKaiUI.getMainUI().jTabbedPane.getSelectedComponent();
panel.write("<div style=\"color:black; font-size:" + JKaiUI.getConfig().getConfigInt(SystemFontSize) + "px;\"> -- " + " Received an ask comamnd from "+ msg.getUser() +" Command:" + msg.getMessage() + "</div>");
- //コマンドの送信
+ //コマンドの送信
String sendtext = JKaiUIAskCommands(msg.getMessage().replaceFirst("%ask\\s+", ""));
if (sendtext != null) {
@@ -922,7 +875,7 @@ private String JKaiUIAskcommand(InMessage msg) {
return null;
}
}
- //通常のテキスト
+ //通常のテキスト
return msg.getMessage();
}
@@ -952,27 +905,27 @@ private String JKaiUICommands(String text) {
//create private arena
//create
- //create description maxplayernum password
- //create description maxplayernum (no pass)
- //create description (maxplayernum=4) (no pass)
+ //create description maxplayernum password
+ //create description maxplayernum (no pass)
+ //create description (maxplayernum=4) (no pass)
if (tmp[0].equalsIgnoreCase("create")) {
String description = "";
String password = "";
- int maxPlayers = 4;
+ int maxPlayers;
String maxPlayersString = "";
if (tmp.length == 1) {
//create
JKaiUI.getArenaMode().clickcreateArenaButton();
} else if (tmp.length == 2) {
- //create description (maxplayernum=4) (no pass)
+ //create description (maxplayernum=4) (no pass)
description = tmp[1];
} else if (tmp.length == 3) {
- //create description maxplayernum (no pass)
+ //create description maxplayernum (no pass)
description = tmp[1];
maxPlayersString = tmp[2];
} else if (tmp.length == 4) {
- //create description maxplayernum password
+ //create description maxplayernum password
description = tmp[1];
maxPlayersString = tmp[2];
password = tmp[3];
@@ -984,7 +937,7 @@ private String JKaiUICommands(String text) {
error = java.util.ResourceBundle.getBundle("pt/jkaiui/ui/Bundle").getString("MSG_InvalidMaxPlayers");
}
- maxPlayers = Integer.parseInt(maxPlayersString.length() > 0 ? maxPlayersString : "0");
+ maxPlayers = Integer.parseInt(maxPlayersString.length() > 0 ? maxPlayersString : "4");
if (!description.matches("^.{0,20}$")) {
@@ -1005,7 +958,7 @@ private String JKaiUICommands(String text) {
out.setPassword(new KaiString(password));
out.setMaxPlayers(maxPlayers);
- JKaiUI.getManager().getExecuter().execute(out);
+ ActionExecuter.execute(out);
return "create arena";
}
@@ -1083,7 +1036,7 @@ private String JKaiUICommands(String text) {
Pattern p2 = Pattern.compile("^#([0-9]+)");
Matcher m2 = p2.matcher(tmp[1]);
- Arena arena = new Arena();
+ Arena arena;
if (m2.matches()) {
if (Integer.parseInt(m2.group(1)) > 0) {
Vector BookmarkVector = JKaiUI.getMainUI().bookmarkVector;
@@ -1092,13 +1045,13 @@ private String JKaiUICommands(String text) {
if (JKaiUI.CURRENT_MODE != JKaiUI.ARENA_MODE) {
JKaiUI.getMainUI().jButtonArenaMode.doClick();
}
- JKaiUI.getManager().enterArena(arena);
+ Manager.enterArena(arena);
}
}
return null;
}
- //pm フレ#1
+ //pm フレ#1
if (tmp[0].equalsIgnoreCase("pm")) {
Pattern p2 = Pattern.compile("^#([0-9]+)");
@@ -1167,7 +1120,7 @@ private String JKaiUICommands(String text) {
return null;
}
- //help コマンド一覧 コマンド説明
+ //help コマンド一覧 コマンド説明
if (tmp[0].equalsIgnoreCase("help")) {
String commands = "send ver help show phrase emoti setconfig config diag go gofull arenapm follow pm bookmark "
+ "chatreset chatlock cahtunlock logwindow exit connect disconnect messengermode arenamode diagmode "
@@ -1188,7 +1141,8 @@ private String JKaiUICommands(String text) {
Object obj = listmodel.getElementAt(i);
if (obj instanceof User) {
User user = (User) obj;
- str.append(user.getUser() + " ");
+ str.append(user.getUser());
+ str.append(" ");
}
}
@@ -1202,7 +1156,8 @@ private String JKaiUICommands(String text) {
Object obj = listmodel.getElementAt(i);
if (obj instanceof User) {
User user = (User) obj;
- str.append(user.getUser()+" ");
+ str.append(user.getUser());
+ str.append(" ");
}
}
@@ -1216,7 +1171,10 @@ private String JKaiUICommands(String text) {
Object obj = listmodel.getElementAt(i);
if (obj instanceof Arena) {
Arena arena = (Arena) obj;
- str.append(arena.getVector() + ":" + arena.getDescription() + " ");
+ str.append(arena.getVector());
+ str.append(":");
+ str.append(arena.getDescription());
+ str.append(" ");
}
}
@@ -1256,7 +1214,7 @@ private String JKaiUICommands(String text) {
Pattern p2 = Pattern.compile("^#([0-9]+)");
Matcher m2 = p2.matcher(tmp[1]);
- String emot = "";
+ String emot;
if (m2.matches()) {
if (Integer.parseInt(m2.group(1)) > 0) {
@@ -1273,7 +1231,7 @@ private String JKaiUICommands(String text) {
return null;
}
- //setconfig コマンド名 設定値
+ //setconfig コマンド名 設定値
if (tmp[0].equalsIgnoreCase("setconfig")) {
if (tmp.length > 2) {
try {
@@ -1282,7 +1240,7 @@ private String JKaiUICommands(String text) {
System.out.println("error nothing config:" + e);
}
try {
- String str = text.replaceFirst(tmp[0]+"\\s+", "").replaceFirst(tmp[1]+"\\s+", "");//3番目以降の値を取り出す
+ String str = text.replaceFirst(tmp[0]+"\\s+", "").replaceFirst(tmp[1]+"\\s+", "");//3番目以降の値を取り出す
JKaiUI.getConfig().loadtoFileConfig(tmp[1] + ":" + str);
JKaiUI.getConfig().saveConfig();
@@ -1310,7 +1268,7 @@ private String JKaiUICommands(String text) {
Pattern p2 = Pattern.compile("^#([0-9]+)");
Matcher m2 = p2.matcher(tmp[1]);
- String texttmp = text.replaceFirst(tmp[0]+"\\s+", "");//2番目以降の値を取り出す
+ String texttmp = text.replaceFirst(tmp[0]+"\\s+", "");//2番目以降の値を取り出す
if (tmp[1].equalsIgnoreCase("parent")) {
JKaiUI.getArenaMode().clickgoBackButton();
@@ -1362,7 +1320,7 @@ private String copydiaginfo(String kinds){
String textbuf = "";
if (kinds.equalsIgnoreCase("all")) {
- StringBuffer strbuf = new StringBuffer("Diags infomation \n\n");//保存する設定情報
+ StringBuilder strbuf = new StringBuilder("Diags infomation \n\n");//保存する設定情報
strbuf.append(copydiaginfo("server"));
strbuf.append(copydiaginfo("network"));
@@ -1373,12 +1331,12 @@ private String copydiaginfo(String kinds){
}
if (kinds.equalsIgnoreCase("server")) {
Diags diags = (Diags) model.get(0);
- textbuf = new String("OrbServer: " + diags.getValue1());
+ textbuf = "OrbServer: " + diags.getValue1();
}
if (kinds.equalsIgnoreCase("network")) {
Diags diags = (Diags) model.get(1);
// textbuf = new String("Network: " + diags.getValue1() +" "+ diags.getValue2());
- textbuf = new String("Network: " + diags.getValue2());
+ textbuf = "Network: " + diags.getValue2();
}
// if (m.group(2).equalsIgnoreCase("ipport")) {
@@ -1387,31 +1345,31 @@ private String copydiaginfo(String kinds){
// }
if (kinds.equalsIgnoreCase("reachable")) {
Diags diags = (Diags) model.get(1);
- textbuf = new String("Network: " + diags.getValue2());
+ textbuf = "Network: " + diags.getValue2();
}
if (kinds.equalsIgnoreCase("hardware")) {
Diags diags = (Diags) model.get(2);
- textbuf = new String("Hardware: " + diags.getValue1() + " " + diags.getValue2());
+ textbuf = "Hardware: " + diags.getValue1() + " " + diags.getValue2();
}
if (kinds.equalsIgnoreCase("nic")) {
Diags diags = (Diags) model.get(2);
- textbuf = new String("Hardware: " + diags.getValue1());
+ textbuf = "Hardware: " + diags.getValue1();
}
if (kinds.equalsIgnoreCase("lib")) {
Diags diags = (Diags) model.get(2);
- textbuf = new String("Hardware: " + diags.getValue2());
+ textbuf = "Hardware: " + diags.getValue2();
}
if (kinds.equalsIgnoreCase("engine")) {
Diags diags = (Diags) model.get(3);
- textbuf = new String("Engine: " + diags.getValue1() + " " + diags.getValue2());
+ textbuf = "Engine: " + diags.getValue1() + " " + diags.getValue2();
}
if (kinds.equalsIgnoreCase("ver")) {
Diags diags = (Diags) model.get(3);
- textbuf = new String("Engine: " + diags.getValue1());
+ textbuf = "Engine: " + diags.getValue1();
}
if (kinds.equalsIgnoreCase("platform")) {
Diags diags = (Diags) model.get(3);
- textbuf = new String("Engine: " + diags.getValue2());
+ textbuf = "Engine: " + diags.getValue2();
}
return textbuf;
}
View
94 src/pt/jkaiui/ui/tools/CommandExecuter.java
@@ -0,0 +1,94 @@
+package pt.jkaiui.ui.tools;
+
+/*
+ * To change this template, choose Tools | Templates and open the template in
+ * the editor.
+ */
+import java.io.*;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *
+ * @author yuuakron
+ */
+public class CommandExecuter implements Runnable {
+
+ private StringWriter strWriter;
+ private PrintWriter pwriter;
+ private BufferedReader buffReader;
+
+ public CommandExecuter() {
+ }
+
+ private String doExec(List<String> commands) throws IOException {
+
+ ProcessBuilder pb = new ProcessBuilder(commands);
+ Process proc = pb.start();
+ buffReader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
+ strWriter = new StringWriter();
+ pwriter = new PrintWriter(strWriter);
+
+
+ Thread th = new Thread(this);
+
+ th.start();
+
+ try {
+
+ th.join();
+
+ } catch (InterruptedException e) {
+
+ throw new IOException("Command Exec Failed");
+
+ }
+
+ buffReader.close();
+
+ pwriter.close();
+
+ String temp = strWriter.toString();
+
+ if ((temp.length() > 1) && (temp.substring(temp.length() - 1).getBytes()[0] == 10)) {
+
+ temp = temp.substring(0, temp.length() - 1);
+
+ }
+
+ return temp;
+
+ }
+
+ public void doCommand(String command) {
+ try {
+ ArrayList<String> commands = new ArrayList<String>();
+ commands.add("/bin/sh");
+ commands.add("-c");
+ commands.add(command+" &");
+ doExec(commands);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void run() {
+
+ String line;
+
+ try {
+
+ while ((line = buffReader.readLine()) != null) {
+
+ pwriter.println(line);
+
+ }
+
+ } catch (IOException e) {
+
+ e.printStackTrace();
+
+ }
+ }
+}
View
15 src/pt/jkaiui/ui/tools/Say.java
@@ -0,0 +1,15 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package pt.jkaiui.ui.tools;
+
+/**
+ *
+ * @author yuuakron
+ */
+public class Say{
+ public static void speakString(String speakstr) {
+ new CommandExecuter().doCommand("say -v Kyoko " + speakstr);
+ }
+}

0 comments on commit 93da9fe

Please sign in to comment.