package chat; import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.text.*; import javax.swing.event.*; import java.net.URL; import lava.net.psyc.UNI; /** * **/ public class UserFrame extends JFrame { /** * **/ private UserFrameListener _listener; /** * **/ private String _context; /** * **/ private UNI _identification; /** * **/ private JPanel _mainPanel; /** * **/ private JPanel _buttonPanel; /** * **/ private JPanel _infoPanel; /** * **/ private JButton _button1; /** * **/ private JButton _button2; /** * **/ private JButton _button3; /** * **/ private JButton _button4; /** * **/ public UserFrame(UserFrameListener listener, // boolean editable, String context, UNI identification, // String nickname, String name, String information, URL url) { _context = context; _identification = identification; _listener = listener; String _ident = identification == null ? "" : // identification.toString(); String _nickname = nickname == null ? "" : nickname; String _name = name == null ? "" : name; String _information = information == null ? "" : information; String _url = url == null ? "" : url.toString(); setTitle(_name); setResizable(false); getContentPane().setLayout(new BorderLayout()); _mainPanel = new JPanel(); _mainPanel.setLayout(new BorderLayout(0,2)); // Buttons und deren Listener erzeugen _button1 = new JButton("Add Buddy"); if(editable) _button2.setEnabled(false); _button2 = new JButton("Talk"); if(editable) _button2.setEnabled(false); _button2.addActionListener(new ActionListener() { /** * **/ public void actionPerformed(ActionEvent ae) { _listener.talk(_context,_identification); } } ); _button3 = new JButton("Apply"); if(!editable) _button3.setEnabled(false); _button4 = new JButton("Dismiss"); _button4.addActionListener(new ActionListener() { /** * **/ public void actionPerformed(ActionEvent ae) { UserFrame.this.dispose(); } } ); _buttonPanel = new JPanel(); _buttonPanel.setLayout(new GridLayout(0,1)); _buttonPanel.setBorder(new EmptyBorder(4,4,4,4)); _buttonPanel.setBackground(Properties.BG_COLOR); _buttonPanel.add(_button1); _buttonPanel.add(_button2); _buttonPanel.add(_button3); _buttonPanel.add(_button4); // hier den groessten button nehmen //_buttonPanel.setMaximumSize(_button1.getSize()); JTextField f; _infoPanel = new JPanel(); _infoPanel.setBackground(Properties.BG_COLOR); _infoPanel.setLayout(new GridBagLayout()); GridBagConstraints cl = new GridBagConstraints(); cl.anchor = cl.WEST; GridBagConstraints c = new GridBagConstraints(); c.gridwidth = c.REMAINDER; c.fill = c.HORIZONTAL; _infoPanel.add(new JLabel("Identification"),cl); f = new JTextField(_ident); f.setColumns(20); if(!editable) f.setEditable(false); _infoPanel.add(f,c); _infoPanel.add(new JLabel("Nickname"),cl); f = new JTextField(_nickname); if(!editable) f.setEditable(false); _infoPanel.add(f,c); _infoPanel.add(new JLabel("Name"),cl); f = new JTextField(_name); if(!editable) f.setEditable(false); _infoPanel.add(f,c); _infoPanel.add(new JLabel("Information"),cl); f = new JTextField(_information); if(!editable) f.setEditable(false); _infoPanel.add(f,c); _infoPanel.add(new JLabel("Homepage"),cl); f = new JTextField(_url); if(!editable) f.setEditable(false); _infoPanel.add(f,c); _mainPanel.add(_infoPanel,BorderLayout.CENTER); _mainPanel.add(_buttonPanel,BorderLayout.EAST); getContentPane().add(_mainPanel,BorderLayout.CENTER); pack(); setVisible(true); } /** * **/ public static void main(String[] args) throws Exception { UserFrame c = new UserFrame(null,true,// null,new UNI("psyc://xanadu.lava.de/holbe"),// "BitKoenig",// "Mario Holbe",// "No more Informations",// new URL("http://www.rz.tu-ilmenau.de/~holbe/")); c.addWindowListener(new WindowAdapter() { /** * **/ public void windowClosing(WindowEvent we) { System.exit(0); } /** * **/ public void windowClosed(WindowEvent we) { System.exit(0); } } ); } }