package net.jxta.chat.interfaces;
import java.awt.Color;
import java.awt.ComponentOrientation;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.Enumeration;
import javax.swing.AbstractButton;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.border.EtchedBorder;
import javax.swing.border.SoftBevelBorder;
import net.jxta.chat.core.ChatHandler;
import net.jxta.chat.core.PeerCore;
import net.jxta.peergroup.PeerGroup;
/**
* @author Matteo Tanca
* @version 0.1
* Interfaccia di chat
*/
public class ChatInterface extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel mainPanel = null;
/*
* Stringa di default che segue l'identificatore del mittente nella
* stampa dei messaggi
*/
public static final String SEPARATOR = " scrive:\n";
private String chatTitle = null;
private boolean historyHasToScroll = true;
private ChatHandler handler = null;
private ChatInterfaceEventListener interfaceEventListener = null;
private DefaultListModel peerListModel = null;
private String nick;
private JButton refreshUsersButton = null;
private JButton sendMsgButton = null;
private JLabel listLabel = null;
private JLabel jLabel = null;
private JMenuBar jJMenuBar = null;
private JScrollPane jScrollPane = null;
private JList peerList = null;
private JCheckBox autoScrollCheckBox = null;
private JScrollPane jScrollPane1 = null;
private JTextArea historyArea = null;
private JScrollPane jScrollPane2 = null;
private JTextArea inputArea = null;
private JMenu jMenu = null;
private JMenuItem saveHistoryMenuItem = null;
private JMenuItem exitMenuItem = null;
private JMenu jMenu1 = null;
private JMenu jMenu2 = null;
private JMenuItem setNickname = null;
private JRadioButtonMenuItem onlineMenuItem = null;
private JRadioButtonMenuItem awayMenuItem = null;
private JRadioButtonMenuItem backSoonMenuItem = null;
private JRadioButtonMenuItem busyMenuItem = null;
private JRadioButtonMenuItem offlineMenuItem = null;
private ButtonGroup stats = null;
private JMenu jMenu3 = null;
private JCheckBoxMenuItem logChangesCheckBox = null;
private JMenuItem changeBackgroundItem = null;
private JMenuItem changeFontsMenuItem = null;
private JMenuItem changeTextColorItem = null;
private JPanel jPanel = null;
public ChatInterface (PeerCore pc, PeerGroup chat, String nickName) {
super();
chatTitle = nickName + " @ " + chat.getPeerGroupName() + " [" + chat.getPeerGroupAdvertisement().getDescription() + "] (" + "GID: " + chat.getPeerGroupID() + ")";
initialize();
handler = new ChatHandler(pc, chat, this, peerListModel, nickName);
nick = nickName;
setVisible(true);
interfaceEventListener = new ChatInterfaceEventListener(this, handler, inputArea);
initializeListeners();
}
/**
* Metodo privato di inizializzazione dell'interfaccia
* di chat
*/
private void initialize() {
this.setTitle(chatTitle);
this.setSize(576, 494);
this.setContentPane(getMainPanel());
this.setJMenuBar(getJJMenuBar());
}
/**
* Metodo privato di inizializzazione del pannello principale
* @return JPanel mainPanel
*/
private JPanel getMainPanel() {
if (mainPanel == null) {
GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
gridBagConstraints8.insets = new Insets(1, 1, 2, 0);
gridBagConstraints8.gridy = 1;
gridBagConstraints8.fill = GridBagConstraints.BOTH;
gridBagConstraints8.weightx = 1.0D;
gridBagConstraints8.weighty = 1.0D;
gridBagConstraints8.gridx = 1;
GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
gridBagConstraints7.insets = new Insets(0, 1, 0, 4);
gridBagConstraints7.gridy = 0;
gridBagConstraints7.ipadx = 228;
gridBagConstraints7.ipady = 15;
gridBagConstraints7.gridx = 1;
GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
gridBagConstraints6.insets = new Insets(0, 0, 0, 1);
gridBagConstraints6.gridy = 0;
gridBagConstraints6.ipadx = 63;
gridBagConstraints6.ipady = 15;
gridBagConstraints6.gridx = 0;
GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
gridBagConstraints5.insets = new Insets(2, 1, 0, 3);
gridBagConstraints5.gridy = 2;
gridBagConstraints5.fill = GridBagConstraints.HORIZONTAL;
gridBagConstraints5.gridx = 0;
GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
gridBagConstraints4.fill = GridBagConstraints.BOTH;
gridBagConstraints4.gridx = 0;
gridBagConstraints4.gridy = 1;
gridBagConstraints4.ipadx = -91;
gridBagConstraints4.ipady = 252;
gridBagConstraints4.weightx = 0.15D;
gridBagConstraints4.weighty = 1.0;
gridBagConstraints4.insets = new Insets(0, 0, 1, 1);
GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
gridBagConstraints3.insets = new Insets(2, 8, 0, 7);
gridBagConstraints3.gridy = 2;
gridBagConstraints3.ipadx = 238;
gridBagConstraints3.fill = GridBagConstraints.HORIZONTAL;
gridBagConstraints3.gridx = 1;
mainPanel = new JPanel();
listLabel = new JLabel();
listLabel.setHorizontalAlignment(SwingConstants.CENTER);
listLabel.setText("Stato degli utenti");
jLabel = new JLabel();
jLabel.setHorizontalAlignment(SwingConstants.CENTER);
jLabel.setText("Cronologia dei messaggi");
mainPanel.setLayout(new GridBagLayout());
mainPanel.setBorder(new SoftBevelBorder(SoftBevelBorder.RAISED));
mainPanel.add(getSendMsgButton(), gridBagConstraints3);
mainPanel.add(getJScrollPane(), gridBagConstraints4);
mainPanel.add(getRefreshUsersButton(), gridBagConstraints5);
mainPanel.add(listLabel, gridBagConstraints6);
mainPanel.add(jLabel, gridBagConstraints7);
mainPanel.add(getJPanel(), gridBagConstraints8);
}
return mainPanel;
}
/**
* Metodo privato di inizializzazione del bottone 'Aggiorna stato utenti'
* @return JButton refreshUsersButton
*/
private JButton getRefreshUsersButton() {
if (refreshUsersButton == null) {
refreshUsersButton = new JButton();
refreshUsersButton.setToolTipText("Clicca per richiedere un aggiornamento forzato dello stato degli utenti");
refreshUsersButton.setName("Refresh");
refreshUsersButton.setText("Aggiorna stato utenti");
}
return refreshUsersButton;
}
/**
* Metodo privato di inizializzazione del bottone 'Invia messaggio'
* @return JButton sendMsgButton
*/
private JButton getSendMsgButton() {
if (sendMsgButton == null) {
sendMsgButton = new JButton();
sendMsgButton.setToolTipText("Premi per inviare il messaggio digitato");
sendMsgButton.setName("SendMsg");
sendMsgButton.setText("Invia messaggio");
}
return sendMsgButton;
}
/**
* Metodo privato di inizializzazione della barra del menu'
* @return JMenuBar
*/
private JMenuBar getJJMenuBar() {
if (jJMenuBar == null) {
jJMenuBar = new JMenuBar();
jJMenuBar.setPreferredSize(new Dimension(0, 20));
stats = new ButtonGroup();
jJMenuBar.add(getJMenu());
jJMenuBar.add(getJMenu1());
jJMenuBar.add(getJMenu2());
jJMenuBar.add(getJMenu3());
}
return jJMenuBar;
}
/**
* Metodo privato di inizializzazione del pannello di scorrimento in cui
* e' inserita la lista degli utenti
* @return JScrollPane
*/
private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setBorder(BorderFactory.createCompoundBorder(BorderFact