/*
* ChatPanel.java
*
* Created on November 25, 2004, 7:12 PM
*/
package pt.jkaiui.ui;
import javax.swing.text.Document;
import javax.swing.JMenuItem;
import javax.swing.JTextField;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkEvent.EventType;
import java.util.Calendar;
import java.util.ArrayList;
import java.util.Vector;
import java.util.HashMap;
import java.net.URI;
import java.net.URL;
import java.net.URLEncoder;
import java.awt.Desktop;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.Component;
import pt.jkaiui.JKaiUI;
import pt.jkaiui.core.ChatMessage;
import pt.jkaiui.core.OutMessage;
import pt.jkaiui.core.User;
import pt.jkaiui.core.messages.*;
import pt.jkaiui.core.KaiString;
import pt.jkaiui.core.Arena;
import pt.jkaiui.manager.ActionExecuter;
import pt.jkaiui.ui.modes.MessengerModeListModel;
import static pt.jkaiui.core.KaiConfig.ConfigTag.*;
/**
*
* @author pedro
*/
public class ChatPanel extends javax.swing.JPanel {
public static final int MAXSIZE = 100000;
private boolean closable = true;
private String name;
protected Calendar date;
private String hyperlinkbuf = "";
private ArrayList lockbuf = new ArrayList();
/** Creates new form ChatPanel */
public ChatPanel() {
initComponents();
jEditorPane.setContentType("text/html");
jEditorPane.setComponentPopupMenu(chatPopupMenu);
jTextFieldInput.setComponentPopupMenu(chatInputPopupMenu);
date = Calendar.getInstance();
comboSendCoding.setVisible(false);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
chatPopupMenu = new javax.swing.JPopupMenu();
CopytoClipboard = new javax.swing.JMenuItem();
CopytoChatfield = new javax.swing.JMenuItem();
SearchwithGoogle = new javax.swing.JMenuItem();
OpenUrl = new javax.swing.JMenuItem();
AllSelect = new javax.swing.JMenuItem();
GotoParentArena = new javax.swing.JMenuItem();
CreatePrivateArena = new javax.swing.JMenuItem();
GotoArena = new javax.swing.JMenu();
FollowFriend = new javax.swing.JMenu();
OpenPM = new javax.swing.JMenu();
Bookmarks = new javax.swing.JMenu();
chatInputPopupMenu = new javax.swing.JPopupMenu();
CopytoClipboardInput = new javax.swing.JMenuItem();
Paste = new javax.swing.JMenuItem();
Cut = new javax.swing.JMenuItem();
AllSelectInput = new javax.swing.JMenuItem();
jPanelInput = new javax.swing.JPanel();
jToggleButton1 = new javax.swing.JToggleButton();
jTextFieldInput = new javax.swing.JTextField();
jButtonClose = new javax.swing.JButton();
checklockchat = new javax.swing.JCheckBox();
buttonReset = new javax.swing.JButton();
comboSendCoding = new javax.swing.JComboBox();
jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jEditorPane = new javax.swing.JEditorPane();
chatPopupMenu.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
}
public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
chatPopupMenuPopupMenuWillBecomeInvisible(evt);
}
public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
chatPopupMenuPopupMenuWillBecomeVisible(evt);
}
});
CopytoClipboard.setText("Copy to Clipboard");
CopytoClipboard.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CopytoClipboardActionPerformed(evt);
}
});
chatPopupMenu.add(CopytoClipboard);
CopytoChatfield.setText("Copy to Chat");
CopytoChatfield.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CopytoChatfieldActionPerformed(evt);
}
});
chatPopupMenu.add(CopytoChatfield);
SearchwithGoogle.setText("Serach with Google");
SearchwithGoogle.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
SearchwithGoogleActionPerformed(evt);
}
});
chatPopupMenu.add(SearchwithGoogle);
OpenUrl.setText("Open URL");
OpenUrl.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
OpenUrlActionPerformed(evt);
}
});
chatPopupMenu.add(OpenUrl);
AllSelect.setText("All Select");
AllSelect.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
AllSelectActionPerformed(evt);
}
});
chatPopupMenu.add(AllSelect);
GotoParentArena.setText("Go to Parent Arena");
GotoParentArena.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
GotoParentArenaActionPerformed(evt);
}
});
chatPopupMenu.add(GotoParentArena);
CreatePrivateArena.setText("CreateArena");
CreatePrivateArena.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CreatePrivateArenaActionPerformed(evt);
}
});
chatPopupMenu.add(CreatePrivateArena);
GotoArena.setText("GotoArena");
chatPopupMenu.add(GotoArena);
FollowFriend.setText("FollowFriend");
chatPopupMenu.add(FollowFriend);
OpenPM.setText("OpenPM");
chatPopupMenu.add(OpenPM);
Bookmarks.setText("Bookmarks");
chatPopupMenu.add(Bookmarks);
CopytoClipboardInput.setText("Copy to Clipboard");
CopytoClipboardInput.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CopytoClipboardInputActionPerformed(evt);
}
});
chatInputPopupMenu.add(CopytoClipboardInput);
Paste.setText("Paste");
Paste.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
PasteActionPerformed(evt);
}
});
chatInputPopupMenu.add(Paste);
Cut.setText("Cut");
Cut.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CutActionPerformed(evt);
}
});
chatInputPopupMenu.add(Cut);
AllSelectInput.setText("All Select");
AllSelectInput.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
AllSelectInputActionPerformed(evt);
}
});
chatInputPopupMenu.add(AllSelectInput);
setMinimumSize(new java.awt.Dimension(300, 200));
setPreferredSize(new java.awt.Dimension(500, 400));
setLayout(new java.awt.BorderLayout());
jPanelInput.setLayout(new javax.swing.BoxLayout(jPanelInput, javax.swing.BoxLayout.LINE_AXIS));
jToggleButton1.setText("phrase");
jToggleButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
jToggleButton1MousePressed(evt);
}
});
jPanelInput.add(jToggleButton1);
jTextFieldInput.setColumns(30);
jTextFieldInput.setFont(new java.awt.Font("Dialog", 0, 12));
jTextFieldInput.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
jTextInputKeyPressed(evt);
}
public void keyPressed(java.awt.event.KeyEvent evt) {
jTextFieldInputKeyPressed(evt);
}
public void keyReleased(java.awt.event.KeyEvent evt) {
jTextFieldInputKeyReleased(evt);
}
});
jPanelInput.add(jTextFieldInput);
jButtonClose.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pt/jkaiui/ui/resources/closechat.png"))); // NOI18N
jButtonClose.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonCloseActionPerformed(evt);
}
});
jPanelInput.add(jButtonClose);
checklockchat.setText("lock");
checklockchat.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
checklockchatActionPerformed(evt);
}
});
jPanelInput.add(checklockchat);
buttonReset.setText("reset");
buttonReset.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonResetActionPerformed(evt);
}
});
jPanelInput.add(buttonReset);
comboSendCoding.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "JKaiUI(7.4.18)", "JKaiUI(7.4.22)", "WebUI(7.4.18)", "WebUI(7.4.22)", "GUI(7.4.18)", "GUI(7.4.22)" }));
jPanelInput.add(comboSendCoding);
add(jPanelInput, java.awt.BorderLayout.SOUTH);
jPanel1.setLayout(new java.awt.BorderLayout());
jEditorPane.setContentType("text/html");
jEditorPane.setEditable(false);
jEditorPane.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jEditorPaneMouseClicked(evt);
}
});
jEditorPane.addHyperlinkListener(new javax.swing.event.HyperlinkListener() {
public void hyperlinkUpdate(javax.swing.event.HyperlinkEvent evt) {
jEditorPaneHyperlinkUpdate(evt);
}
});
jEditorPane.addHierarchyBoundsListener(new java.awt.event.HierarchyBoundsListener() {
public void ancestorMoved(java.awt.event.HierarchyEvent evt) {
}
public void ancestorResized(java.awt.event.HierarchyEvent evt) {
jEditorPaneAncestorResized(evt);
}
});
jScrollPane1.setViewportView(jEditorPane);
jPanel1.add(jScrollPane1, java.awt.BorderLayout.CENTER);
add(jPanel1, java.awt.BorderLayout.CENTER);
}// </editor-fold>//GEN-END:initComponents
private void jTextInputKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextInputKeyPressed
// System.out.println(evt.getKeyChar() + ":" + evt.getKeyCode());
/*
if (evt.getKeyChar() == evt.VK_ENTER) {
String text = "";
try {
// text = new String(jTextFieldInput.getText().getBytes("Windows-31j"), "Windows-31j");
text = jTextFieldInput.getText();
} catch (Exception e) {
System.out.println("chatinput:" + e);
}
if (text.length() == 0) {
return;
}
jTextFieldInput.setText("");
text = JKaiUIcommand(text);
if (text == null) {
return;
}
// Build a OutMessage and pass it to ChatManager
// Now Im testing a few messages
OutMessage msg = new OutMessage();
if (!isClosable()) {
msg.setType(ChatMessage.PUBLIC_MESSAGE);
} else {
msg.setType(ChatMessage.PRIVATE_MESSAGE);
msg.setUser(new User(name));
}
msg.setMessage(text);
JKaiUI.getChatManager().processMessage(msg);
} else if (evt.getKeyChar() == evt.VK_ESCAPE) {
if (jTextFieldInput.getText().length() == 0 && isClosable()) {
// close
JKaiUI.getChatManager().closeChat(this);
} else {
jTextFieldInput.setText("");
}
}else if(evt.getKeyCode() == evt.VK_UP){
System.out.println("keyup");
String historytmp = JKaiUI.getChatManager().previouschathistory();
if (historytmp != null) {
System.out.println("keyup");
jTextFieldInput.setText(historytmp);
}
}else if(evt.getKeyCode() == evt.VK_DOWN){
System.out.println("keydown");
String historytmp = JKaiUI.getChatManager().nextchathistory();
if (historytmp != null) {
System.out.println("keyup");
jTextFieldInput.setText(historytmp);
}
}
*/
}//GEN-LAST:event_jTextInputKeyPressed
private void CopytoClipboardActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CopytoClipboardActionPerformed
jEditorPane.copy();
}//GEN-LAST:event_CopytoClipboardActionPerformed
private void CopytoChatfieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CopytoChatfieldActionPerformed
try {
jTextFieldInput.getDocument().insertString(jTextFieldInput.getCaretPosition(), jEditorPane.getSelectedText(), null);
} catch (Exception e) {
System.out.println("copytochat:" + e);
}
}//GEN-LAST:event_CopytoChatfieldActionPerformed
private void AllSelectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AllSelectActionPerformed
jEditorPane.selectAll();
}//GEN-LAST:event_AllSelectActionPerformed
private void SearchwithGoogleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SearchwithGoogleActionPerformed
try {
// System.out.println(URLEncoder.encode(jEditorPane.getSelectedText(), "utf-8" ));
Desktop.getDesktop().browse(new URI("http://www.google.co.jp/search?q=" + URLEncoder.encode(jEditorPane.getSelectedText(), "utf-8")));
} catch (Exception e) {
System.out.println("SearchwithGoogle:" + e);
}
}//GEN-LAST:event_SearchwithGoogleActionPerformed
private void OpenUrlActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OpenUrlActionPerformed
try {
Desktop.getDesktop().browse(new URI(jEditorPane.getSelectedText()));
} catch (Exception e) {
System.out.println("OpenURL:" + e);
}
}//GEN-LAST:event_OpenUrlActionPerformed
private void CopytoClipboardInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CopytoClipboardInputActionPerformed
jTextFieldInput.copy();
}//GEN-LAST:event_CopytoClipboardInputActionPerformed
private void AllSelectInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AllSelectInputActionPerformed
jTextFieldInput.selectAll();
}//GEN-LAST:event_AllSelectInputActionPerformed
private void PasteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PasteActionPerformed
jTextFieldInput.paste();
}//GEN-LAST:event_PasteActionPerformed
private void CutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CutActionPerformed
jTextFieldInput.cut();
}//GEN-LAST:event_CutActionPerformed
private void GotoParentArenaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_GotoParentArenaActionPerformed
// if (JKaiUI.MODERATORS.contains(JKaiUI.getConfig().getTag())) {
// JKaiUI.MODERATORS.remove(JKaiUI.getConfig().getTag());
// }
// KaiVectorParent vector = new KaiVectorParent();
// vector.setVector(new KaiString(JKaiUI.ARENA));
// JKaiUI.getManager().getExecuter().execute(vector);
JKaiUI.getArenaMode().clickgoBackButton();
}//GEN-LAST:event_GotoParentArenaActionPerformed
private void chatPopupMenuPopupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_chatPopupMenuPopupMenuWillBecomeVisible
// System.out.println("popup menu open");
//setup gotoarena menu
MessengerModeListModel listmodel = (MessengerModeListModel) JKaiUI.getArenaMode().getListModel();
for (int i = 0; i < listmodel.getSize(); i++) {
Object obj = listmodel.getElementAt(i);
if (obj instanceof Arena) {
Arena arena = (Arena) obj;
JMenuItem gotoarena = new JMenuItem(arena.getName());
GotoArena.add(gotoarena);
gotoarena.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
KaiVectorOut vecOut = new KaiVectorOut();
// System.out.println("gotoarena:"+JKaiUI.ARENA+"/"+evt.getActionCommand());
vecOut.setVector(new KaiString(JKaiUI.ARENA + "/" + evt.getActionCommand()));
ActionExecuter.execute(vecOut);
}
});
}
}
//setup Bookmarks menu
BookmarkVector = JKaiUI.getMainUI().bookmarkVector;
for( int i=0;i < BookmarkVector.size();i++){
Arena arena = (Arena) BookmarkVector.elementAt(i);
final JMenuItem item;
// BookmarkVector.add(arena);
item = new JMenuItem(arena.getName());
item.setFont(Bookmarks.getFont());
Bookmarks.add(item);
// item.setIcon(this.getBookmarkIcon(arena));
item.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Arena arena = new Arena();
for (int i = 0; i < BookmarkVector.size(); i++) {
arena = (Arena) BookmarkVector.get(i);
if (arena.getName().equals(item.getText())) {
if (JKaiUI.CURRENT_MODE != JKaiUI.ARENA_MODE) {
JKaiUI.getMainUI().jButtonArenaMode.doClick();
}
JKaiUI.getManager().enterArena(arena);
return;
}
}
}
});
}
//setup followfriend menu
listmodel = (MessengerModeListModel) JKaiUI.getMessengerMode().getListModel();
FriendsList.clear();
for (int i = 0; i < listmodel.getSize(); i++) {
Object obj = listmodel.getElementAt(i);
if (obj instanceof User) {
User user = (User) obj;
if(user.isOnline()){
FriendsList.put(user.getName(), user);
JMenuItem follow = new JMenuItem(user.getName());
FollowFriend.add(follow);
follow.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
KaiVectorOut vecOut = new KaiVectorOut();
// System.out.println("gotoarena:"+JKaiUI.ARENA+"/"+evt.getActionCommand());
vecOut.setVector(new KaiString(((User)FriendsList.get(evt.getActionCommand())).getCurrentArena()));
ActionExecuter.execute(vecOut);
}
});
}
}
}
//setup openpm menu
for (int i = 0; i < listmodel.getSize(); i++) {
Object obj = listmodel.getElementAt(i);
if (obj instanceof User) {
User user = (User) obj;
if (user.isOnline()) {
// FriendsList.put(user.getName(), user);
JMenuItem openpm = new JMenuItem(user.getName());
OpenPM.add(openpm);
openpm.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
JKaiUI.getChatManager().openChat((User)FriendsList.get(evt.getActionCommand()));
}
});
}
}
}
}//GEN-LAST:event_chatPopupMenuPopupMenuWillBecomeVisible
Vector BookmarkVector = new Vector();
HashMap FriendsList = new HashMap();
private void chatPopupMenuPopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_chatPopupMenuPopupMenuWillBecomeInvisible
// System.out.println("popup menu close");
GotoArena.removeAll();
Bookmarks.removeAll();
OpenPM.removeAll();
FollowFriend.removeAll();
}//GEN-LAST:event_chatPopupMenuPopupMenuWillBecomeInvisible
private void buttonResetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonResetActionPerformed
jEditorPane.setText("");
}//GEN-LAST:event_buttonResetActionPerformed
private void jEditorPaneMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jEditorPaneMouseClicked
jTextFieldInput.requestFocus();
}//GEN-LAST:event_jEditorPaneMouseClicked
private void jEditorPaneHyperlinkUpdate(javax.swing.event.HyperlinkEvent evt) {//GEN-FIRST:event_jEditorPaneHyperlinkUpdate
String tooltipbuf = "";
if (evt.getEventType() == EventType.ACTIVATED) { //�N���b�N���ꂽ��
URL url = evt.getURL();
// System.err.println(url.toString());
//�_�~�[�A�h���X�Ȃ�
if (url.toString().matches("^(https://sites.google.com/site/yuuakron/dummy/)(.*)")) {
//���[�U�[�����`���b�g���͗��ɃR�s�[
// System.out.print("user");
try {
jTextFieldInput.getDocument().insertString(jTextFieldInput.getCaretPosition(), url.toString().replace("https://sites.google.com/site/yuuakron/dummy/", ""), null);
} catch (Exception e) {
System.out.println("hyperlink user:" + e);
}
} else {//�ʏ�̃A�h���X�Ȃ�
//�f�t�H���g�̃u���E�U�[���g���ă����N���\��
Desktop dp = Desktop.getDesktop();
try {
dp.browse(url.toURI());
} catch (Exception ex) {
System.out.println("hyperlink:" + ex);
}
}
} else if (evt.getEventType() == HyperlinkEvent.EventType.ENTERED) {//�����N��ɂ����Ƃ�
tooltipbuf = jEditorPane.getToolTipText();
jEditorPane.setToolTipText(null);
URL url = evt.getURL();
//�A�h���X���摜�Ȃ�
if (url.toString().matches("(.*)\\.(jpg|jpeg|gif|png|bmp)$") && JKaiUI.getConfig().getConfigBoolean(ShowImageMouseoverLink)) {
jEditorPane.setToolTipText("<html><img src=\"" + url.toExternalForm() + "\"></html>");
} else if (url.toString().matches("^(https://sites.google.com/site/yuuakron/dummy/)(.*)")) {//�_�~�[�A�h���X�Ȃ�
try {
hyperlinkbuf = url.toString().replace("https://sites.google.com/site/yuuakron/dummy/", "");
} catch (Exception e) {
System.out.println("hyperlink user entered:" + e);
}
jEditorPane.setToolTipText(hyperlinkbuf);
} else {//���ʂ̃A�h���X�Ȃ�
hyperlinkbuf = url.toString();
/* try {
JEditorPane urlopen = new JEditorPane();
urlopen.setEditable(false);
urlopen.setPage(url);
jEditorPane.setToolTipText(urlopen.getText());
System.out.println(urlopen.getText());
} catch (Exception e) {
System.out.println("hyperlink:" + e);
}
*/
jEditorPane.setToolTipText(url.toString());
}
//�����N��ł̃|�b�v�A�b�v���j���[��ݒ�
CopytoClipboard.removeActionListener(CopytoClipboard.getActionListeners()[0]);
CopytoClipboard.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
StringSelection selection = new StringSelection(hyperlinkbuf);
clipboard.setContents(selection, null);
}
});
CopytoChatfield.removeActionListener(CopytoChatfield.getActionListeners()[0]);
CopytoChatfield.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
try {
jTextFieldInput.getDocument().insertString(jTextFieldInput.getCaretPosition(), hyperlinkbuf, null);
} catch (Exception e) {
System.out.println("copytochat:" + e);
}
}
});
SearchwithGoogle.removeActionListener(SearchwithGoogle.getActionListeners()[0]);
SearchwithGoogle.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
try {
Desktop.getDesktop().browse(new URI("http://www.google.co.jp/search?q=" + URLEncoder.encode(hyperlinkbuf, "utf-8")));
} catch (Exception e) {
System.out.println("SearchwithGoogle:" + e);
}
}
});
OpenUrl.removeActionListener(OpenUrl.getActionListeners()[0]);
OpenUrl.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
try {
Desktop.getDesktop().browse(new URI(hyperlinkbuf));
} catch (Exception e) {
System.out.println("OpenURL:" + e);
}
}
});
} else if (evt.getEventType() == HyperlinkEvent.EventType.EXITED) {//�����N�ォ�痣�ꂽ�Ƃ�
jEditorPane.setToolTipText(tooltipbuf);
//�f�t�H���g�|�b�v�A�b�v���j���[�̓���ɂɖ߂�
CopytoClipboard.removeActionListener(CopytoClipboard.getActionListeners()[0]);
CopytoClipboard.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CopytoClipboardActionPerformed(evt);
}
});
CopytoChatfield.removeActionListener(CopytoChatfield.getActionListeners()[0]);
CopytoChatfield.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CopytoChatfieldActionPerformed(evt);
}
});
SearchwithGoogle.removeActionListener(SearchwithGoogle.getActionListeners()[0]);
SearchwithGoogle.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
SearchwithGoogleActionPerformed(evt);
}
});
OpenUrl.removeActionListener(OpenUrl.getActionListeners()[0]);
OpenUrl.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
OpenUrlActionPerformed(evt);
}
});
}
}//GEN-LAST:event_jEditorPaneHyperlinkUpdate
private void checklockchatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checklockchatActionPerformed
if(!checklock()){
for(int i=0; i<lockbuf.size(); i++){
this.write((String)(lockbuf.get(i)));
}
}
lockbuf.clear();
}//GEN-LAST:event_checklockchatActionPerformed
private void jTextFieldInputKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldInputKeyPressed
// System.out.println(evt.getKeyChar() + ":" + evt.getKeyCode());
if (evt.getKeyChar() == evt.VK_ENTER) {
String text = "";
try {
// text = new String(jTextFieldInput.getText().getBytes("Windows-31j"), "Windows-31j");
text = jTextFieldInput.getText();
} catch (Exception e) {
System.out.println("chatinput:" + e);
}
if (text.length() == 0) {
return;
}
jTextFieldInput.setText("");
// Build a OutMessage and pass it to ChatManager
// Now Im testing a few messages
OutMessage msg = new OutMessage();
if (!isClosable()) {
msg.setType(ChatMessage.PUBLIC_MESSAGE);
} else {
msg.setType(ChatMessage.PRIVATE_MESSAGE);
msg.setUser(new User(name));
}
msg.setMessage(text);
JKaiUI.getChatManager().processMessage(msg);
} else if (evt.getKeyChar() == evt.VK_ESCAPE) {
if (jTextFieldInput.getText().length() == 0 && isClosable()) {
// close
JKaiUI.getChatManager().closeChat(this);
} else {
jTextFieldInput.setText("");
}
} else if (evt.getKeyCode() == evt.VK_UP) {
// System.out.println("keyup");
String historytmp = JKaiUI.getChatManager().previouschathistory();
if (historytmp != null) {
// System.out.println("keyup");
jTextFieldInput.setText(historytmp);
}
} else if (evt.getKeyCode() == evt.VK_DOWN) {
// System.out.println("keydown");
String historytmp = JKaiUI.getChatManager().nextchathistory();
if (historytmp != null) {
// System.out.println("keyup");
jTextFieldInput.setText(historytmp);
}
}
}//GEN-LAST:event_jTextFieldInputKeyPressed
private void jTextFieldInputKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldInputKeyReleased
//System.out.println(evt.getKeyChar() + ":" + evt.getKeyCode());
}//GEN-LAST:event_jTextFieldInputKeyReleased
private void CreatePrivateArenaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CreatePrivateArenaActionPerformed
JKaiUI.getArenaMode().clickcreateArenaButton();
}//GEN-LAST:event_CreatePrivateArenaActionPerformed
private void jToggleButton1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jToggleButton1MousePressed
if(JKaiUI.getMainUI().jPanel2.isVisible()){
JKaiUI.getMainUI().resetEmotIconPane();//�\���ɂb�o�t���\�[�X��H�����߃p�l����\�����̓p�l���̃e�L�X�g�̓��Z�b�g���Ă���
}else if(!JKaiUI.getMainUI().jPanel2.isVisible()){
JKaiUI.getMainUI().initEmotIconPane();
}
JKaiUI.getMainUI().jPanel2.setVisible(!JKaiUI.getMainUI().jPanel2.isVisible());
}//GEN-LAST:event_jToggleButton1MousePressed
private void jButtonCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCloseActionPerformed
JKaiUI.getChatManager().closeChat(this);
}//GEN-LAST:event_jButtonCloseActionPerformed
private void jEditorPaneAncestorResized(java.awt.event.HierarchyEvent evt) {//GEN-FIRST:event_jEditorPaneAncestorResized
this.jScrollPane1.getVerticalScrollBar().setValue(this.jScrollPane1.getVerticalScrollBar().getMaximum());
}//GEN-LAST:event_jEditorPaneAncestorResized
private boolean checklock(){
return checklockchat.isSelected();
}
private void addlockbuf(String chat){
lockbuf.add(chat);
}
/**
* Getter for property name.
* @return Value of property name.
*/
public String getName() {
return this.name;
}
/**
* Setter for property name.
* @param name New value of property name.
*/
public void setName(String name) {
this.name = name;
}
/**
* Getter for property closable.
* @return Value of property closable.
*/
public boolean isClosable() {
return this.closable;
}
/**
* Setter for property closable.
* @param closable New value of property closable.
*/
public void setClosable(boolean closable) {
this.closable = closable;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JMenuItem AllSelect;
private javax.swing.JMenuItem AllSelectInput;
private javax.swing.JMenu Bookmarks;
private javax.swing.JMenuItem CopytoChatfield;
private javax.swing.JMenuItem CopytoClipboard;
private javax.swing.JMenuItem CopytoClipboardInput;
private javax.swing.JMenuItem CreatePrivateArena;
private javax.swing.JMenuItem Cut;
private javax.swing.JMenu FollowFriend;
private javax.swing.JMenu GotoArena;
private javax.swing.JMenuItem GotoParentArena;
private javax.swing.JMenu OpenPM;
private javax.swing.JMenuItem OpenUrl;
private javax.swing.JMenuItem Paste;
private javax.swing.JMenuItem SearchwithGoogle;
public javax.swing.JButton buttonReset;
private javax.swing.JPopupMenu chatInputPopupMenu;
private javax.swing.JPopupMenu chatPopupMenu;
public javax.swing.JCheckBox checklockchat;
private javax.swing.JComboBox comboSendCoding;
public javax.swing.JButton jButtonClose;
private javax.swing.JEditorPane jEditorPane;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanelInput;
private javax.swing.JScrollPane jScrollPane1;
public javax.swing.JTextField jTextFieldInput;
private javax.swing.JToggleButton jToggleButton1;
// End of variables declaration//GEN-END:variables
public void addToMainUI() {
MainUI mainUI = JKaiUI.getMainUI();
if (!isClosable()) {
jButtonClose.setEnabled(false);
}
mainUI.jTabbedPane.add(this);
}
public void removeFromMainUI() {
MainUI mainUI = JKaiUI.getMainUI();
mainUI.jTabbedPane.remove(this);
}
public boolean containMainUI() {
MainUI mainUI = JKaiUI.getMainUI();
Component[] children = JKaiUI.getMainUI().jTabbedPane.getComponents();
for (int i = 0; i < children.length; i++) {
if (children[i] instanceof ChatPanel) {
ChatPanel pane = (ChatPanel) children[i];
if(pane.getName().equals(this.name)){
return true;
}
}
}
return false;
}
public void write(String s) {
//lock chat
if(checklock()){
addlockbuf(s);
return;
}
// Append newline and replace chars
s += "\n";
/* if (this.jEditorPane1.getText().length() > MAXSIZE) {
this.jEditorPane1.setText("");
}
*/
if (!datecheck()) {
this.jEditorPane.setText("");
date = Calendar.getInstance();
}
Document _doc = this.jEditorPane.getDocument();
try {
this.jEditorPane.getEditorKit().read(new java.io.StringReader(s), _doc, _doc.getLength());
if (JKaiUI.getConfig().getConfigBoolean(ShowLatestChat)) {
this.jEditorPane.setCaretPosition(_doc.getLength());
}
} catch (Exception ex) {
// Cannot log the message => print the error to System.out
System.out.println("ChatPanel:" + ex);
throw new IllegalStateException("UIEditorPaneHandler::Error while updating Log EditorPane: " + ex.getMessage());
}
}
public JTextField getInputField() {
return jTextFieldInput;
}
private boolean datecheck() {
Calendar nowdate = Calendar.getInstance();
if ((nowdate.get(Calendar.YEAR) == date.get(Calendar.YEAR))
&& (nowdate.get(Calendar.MONTH) == date.get(Calendar.MONTH))
&& (nowdate.get(Calendar.DAY_OF_MONTH) == date.get(Calendar.DAY_OF_MONTH))) {
return true;
}
return false;
}
public String getSelectedCoding() {
// System.out.println(comboSendCoding.getSelectedItem().toString());
return comboSendCoding.getSelectedItem().toString();
}
public void setVisibleComboSendEncoding(Boolean visible) {
this.comboSendCoding.setVisible(visible);
}
}