]> code.citadel.org Git - citadel.git/blob - shaggy/enterPanel.java
* Got some more parsing in there
[citadel.git] / shaggy / enterPanel.java
1 import javax.swing.*;
2 import java.awt.*;
3 import java.awt.event.*;
4
5 public class enterPanel extends JPanel{
6     roomFrame   rf;
7     roomInfo    ri;
8
9     JTextField  to;
10     JTextArea   msg;
11
12     public enterPanel( final roomFrame rf ) {
13         this.rf = rf;
14         setLayout( new BorderLayout() );
15
16         JPanel  p = new JPanel();
17         p.setBorder( BorderFactory.createTitledBorder(
18                      BorderFactory.createEtchedBorder(), "Recipient" ) );
19         p.setLayout( new BorderLayout() );
20
21         p.add( "Center", to = new JTextField() );
22
23         JButton b = new JButton( "Select" );
24         b.addActionListener( new ActionListener() {
25             public void actionPerformed( ActionEvent e ) {
26                 System.out.println( "User list bialog!" );
27             } } );
28
29         p.add( "East", b );
30
31         add( "North", p );
32
33         to.addActionListener( new ActionListener() {
34             public void actionPerformed( ActionEvent e ) {
35                 msg.requestFocus();
36             } } );
37
38         p = new JPanel();
39         p.setBorder( BorderFactory.createTitledBorder(
40                      BorderFactory.createEtchedBorder(), "Message Text" ) );
41         p.setLayout( new BorderLayout() );
42
43         p.add( "Center", new JScrollPane( msg = new JTextArea(), 
44                   JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
45                   JScrollPane.HORIZONTAL_SCROLLBAR_NEVER ) );
46
47         msg.setLineWrap( true );
48         msg.setWrapStyleWord( true );
49
50         add( "Center", p );
51
52         p = new JPanel();
53
54         p.add( b = new JButton( "Send" ) );
55         b.addActionListener( new ActionListener() {
56             public void actionPerformed( ActionEvent e ) {
57                 String cmd = "ENT0 1|";
58
59                 if( ri.mail ) cmd = cmd + to.getText();
60                 cmd = cmd+"|0|0|0";
61
62                 String  theMsg = wrap( msg.getText() );
63
64                 System.out.println( theMsg );
65                 citadel.me.networkEvent( cmd, theMsg, new CallBack() {
66                     public void run( citReply r ) {
67                         if( r.error() )
68                             citadel.me.warning( r.getArg(0) );
69                         rf.showRoom();
70                     } } );
71             }
72         } );
73
74         p.add( b = new JButton( "Cancel" ) );
75         b.addActionListener( new ActionListener() {
76             public void actionPerformed( ActionEvent e ) {
77                 rf.showRoom();
78             } } );
79
80         add( "South", p );
81     }
82
83     public void refresh( roomInfo ri ) {
84         this.ri = ri;
85         msg.setText( "" );
86         to.setText( "" );
87
88         to.setEnabled( ri.mail );
89     }
90
91     public String wrap( String in ) {
92         StringBuffer    b = new StringBuffer( in );
93         int     last_space = 0, line_length=0;
94         for( int i = 0; i < b.length(); i++ ) {
95             line_length++;
96             if( line_length > 76 ) {
97                 b.setCharAt( last_space, '\n' );
98                 line_length = 0;
99             }
100
101             if( b.charAt(i) == ' ' )
102                 last_space = i;
103         }
104         return b.toString();
105     }
106 }