]> code.citadel.org Git - citadel.git/commitdiff
new classes
authorChilly <chilly@uncensored.citadel.org>
Thu, 5 Aug 1999 16:20:57 +0000 (16:20 +0000)
committerChilly <chilly@uncensored.citadel.org>
Thu, 5 Aug 1999 16:20:57 +0000 (16:20 +0000)
shaggy/pageUserWindow.java [new file with mode: 0644]
shaggy/whoOnlineWindow.java [new file with mode: 0644]

diff --git a/shaggy/pageUserWindow.java b/shaggy/pageUserWindow.java
new file mode 100644 (file)
index 0000000..a6559a5
--- /dev/null
@@ -0,0 +1,97 @@
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
+
+public class pageUserWindow extends JFrame {
+    String     who;
+    Container  c;
+    boolean    done;
+
+    public pageUserWindow() {
+       c = getContentPane();
+       c.setLayout( new BorderLayout() );
+
+       JPanel  p = new JPanel();
+       final JComboBox jcb = new JComboBox();
+
+       p.add( jcb );
+       c.add( "North", jcb );
+       jcb.addActionListener( new ActionListener() {
+           public void actionPerformed( ActionEvent e ) {
+               who = (String)jcb.getSelectedItem();
+           } } );
+
+       citadel.me.networkEvent( "RWHO", new CallBack() {
+           public void run( citReply r ) {
+               if( !r.error() ) {
+                   if( jcb.getModel().getSize() > 0 ) 
+                       jcb.removeAllItems();
+                
+                   String      s;
+                   int         i = 0;
+                   while( (s = r.getLine( i++ )) != null ) {
+                       int     j,k;
+                       j = s.indexOf( "|" ) + 1;
+                       k = s.indexOf( "|", j );
+                       jcb.addItem( s.substring( j, k ) );
+                   }
+               }
+           } } );
+       
+       setUp();
+    }
+
+    public pageUserWindow( String who ) {
+       this.who = who;
+       c = getContentPane();
+       c.setLayout( new BorderLayout() );
+       c.add( "North", new JLabel( "Message to : " + who ) );
+
+       setUp();
+    }
+
+    public void setUp() {
+       JPanel  p = new JPanel();
+       p.setLayout( new BorderLayout() );
+       p.setBorder( BorderFactory.createTitledBorder( 
+                    BorderFactory.createEtchedBorder(), "Message" ) );
+
+       final JTextArea t = new JTextArea();
+       t.setLineWrap( true );
+       t.setWrapStyleWord( true );
+       p.add( "Center", t );
+
+       c.add( "Center", p );
+
+       p = new JPanel();
+       JButton b;
+       p.add( b = new JButton( "Send" ) );
+       b.addActionListener( new ActionListener() {
+           public void actionPerformed( ActionEvent e ) {
+               citadel.me.networkEvent( "SEXP " + who + "|-", t.getText() );
+               closeWin();
+           } } );
+
+       p.add( b = new JButton( "Cancel" ) );
+       b.addActionListener( new ActionListener() {
+           public void actionPerformed( ActionEvent e ) {
+               closeWin();
+           } } );
+       c.add( "South", p );
+
+       addWindowListener( new WindowAdapter() {
+           public void windowClosing( WindowEvent e ) {
+               closeWin();
+           }
+       } );
+
+       citadel.me.registerWindow( this );
+       pack();
+       show();
+    }
+
+    public void closeWin() {
+       citadel.me.removeWindow( this );
+       dispose();
+    }
+}
diff --git a/shaggy/whoOnlineWindow.java b/shaggy/whoOnlineWindow.java
new file mode 100644 (file)
index 0000000..db6954e
--- /dev/null
@@ -0,0 +1,106 @@
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
+import java.util.*;
+
+public class whoOnlineWindow extends JFrame {
+    DefaultListModel   users;
+    JList              theList;
+    boolean            refresh=false;
+
+    public whoOnlineWindow() {
+       setTitle( "Who is online" );
+
+       JPanel  p = new JPanel();
+       p.setLayout( new BorderLayout() );
+       p.setBorder( BorderFactory.createTitledBorder( 
+                                                     BorderFactory.createEtchedBorder(), "Users" ) );
+
+       theList = new JList();
+       users = new DefaultListModel();
+       theList.setModel( users );
+
+       theList.addMouseListener( new MouseAdapter() {
+           public void mouseClicked( MouseEvent e ) {
+               if( refresh) return;
+               int     i = theList.getSelectedIndex();
+               if( i >= 0 )
+                   new pageUserWindow( unpad( (String)users.elementAt( i )) );
+           } } );
+
+       p.add( "Center", new JScrollPane( theList ) );
+       
+       getContentPane().setLayout( new BorderLayout() );
+       getContentPane().add( "Center", p );
+
+       p = new JPanel();
+       JButton b;
+       p.add( b = new JButton( "Refresh" ) );
+       b.addActionListener( new ActionListener() {
+           public void actionPerformed( ActionEvent e ) {
+               refresh();
+           } } );
+
+       p.add( b = new JButton( "Close" ) );
+       b.addActionListener( new ActionListener() {
+           public void actionPerformed( ActionEvent e ) {
+               closeWin();
+           } } );
+
+       getContentPane().add( "South", p );
+
+       addWindowListener( new WindowAdapter() {
+           public void windowClosing( WindowEvent e ) {
+               closeWin();
+           } } );
+
+       citadel.me.registerWindow( this );
+       refresh();
+       pack();
+       show();
+    }
+
+    public void closeWin() {
+       citadel.me.removeWindow( this );
+       dispose();
+    }
+
+    public void refresh() {
+       citadel.me.networkEvent( "RWHO", new CallBack() {
+           public void run( citReply r ) {
+               refresh = true;
+
+               users.removeAllElements();
+
+               int             i = 0;
+               String  s;
+               while( (s = r.getLine( i++ )) != null ) {
+                   int j = s.indexOf( '|' ) + 1;
+                   int k = s.indexOf( '|', j );
+                   int l = s.indexOf( '|', k + 1 );
+                   String      user = s.substring( j, k );
+                   String      room = s.substring( k+1, l );
+                   users.addElement( pad( user, room ) );
+               }
+           refresh=false;
+           }
+       } );
+    }
+
+    public String pad( String u, String r ) {
+       StringBuffer    s = new StringBuffer( u );
+       while( s.length() < 30 )
+           s.append( ' ' );
+       s.append( r );
+       return s.toString();
+    }
+
+    public String unpad( String p ) {
+       StringBuffer    s = new StringBuffer( p.substring( 0, Math.min( 29, p.length() ) ) );
+       while( s.charAt( s.length() - 1) == ' ' )
+           s.deleteCharAt( s.length() -1 );
+       return s.toString();
+    }
+       
+
+}