Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.jboss.remoting.samples.chat.client;
  
  import java.awt.Component;
  
  
  import  org.jboss.logging.Logger;
 
 class Wrapper
 {
    private Object obj;
 
    public Wrapper()
    {
    }
 
    public Wrapper(Object o)
    {
        = o;
    }
 
    public void set(Object o)
    {
        = o;
    }
 
    public Object get()
    {
       return ;
    }
 }
 
 // ****************************************************************
 
 public class LocalStrategy
 {
    protected static final Logger log = Logger.getLogger(LocalStrategy.class);
    
    private RemoteStrategy remoteStrategy;
    private CloseableFrame parent;
    private CreateFrame createFrame;
    private InfoFrame infoFrame;
    private JoinFrame joinFrame;
    private ListFrame listFrame;
    private TalkFrame talkFrame;
    private Thread readThread;
    private boolean isChatting;
    private ShutDownDialog shuttingDownDialog = new ShutDownDialog();
    
    
    public LocalStrategy(CloseableFrame parentRemoteStrategy remoteStrategy)
    {
       this. = parent;
       this. = remoteStrategy;
    }
 
    
    // ****************************************************************
    // ConnectionStrategy
    public void list()
    {
       final Wrapper chatRoomDescriptions = new Wrapper();
 
       Thread t = new Thread()
       {
          public void run()
          {
             try
             {
                chatRoomDescriptions.set(.list());
             }
             catch (ShuttingDownException e)
             {
                SwingUtilities.invokeLater();
             }
             catch (RemoteConnectionException e)
             {
                .error(e);
             }
 
             Runnable r = new Runnable()
             {
                public void run()
                {
                   new ListFrame(LocalStrategy.this, (ArrayListchatRoomDescriptions.get(), ).show();
                }
             };
            SwingUtilities.invokeLater(r);
         }
      };
      t.start();
   }
   
   public void create() throws ConnectionException
   {
       = new CreateFrame(this);
      .show();
   }
   
   // ****************************************************************
   // CreateConnectionStrategy
   public void createChat(final String descriptionfinal ChatMember ownerthrows CreateConnectionException
   {
      Thread t = new Thread()
      {
         TalkFrame talkFrame = new TalkFrame(descriptionowner.get_name(), );
         ChatServer chatServer = null;
         
         public void run()
         {
            try
            {
                = .createChat(descriptionowner);
            }
            catch (ShuttingDownException sde)
            {
               SwingUtilities.invokeLater();
            }
            catch (RemoteConnectionException e)
            {
               .error("Cannot create chat room: " + description);
               .error(e);
            }
            catch (NameInUseException e)
            {
               ..println("Pick a new name");
            }
            Runnable r = new Runnable()
            {
               public void run()
               {
                  .registerStrategy(new TalkConnectionStrategyImpl(owner));
                  .show();
               }
            };
            SwingUtilities.invokeLater(r);
         }
      };
      t.start();
   }
   
   // ****************************************************************
   // JoinConnectionStrategy
   public void join(final ChatInfo chatInfofinal ChatMember newMemberthrows JoinConnectionException
   {
      Thread t = new Thread()
      {
         TalkFrame talkFrame = new TalkFrame(chatInfo.get_description(), newMember.get_name(), );
         Wrapper remoteChatServerWrapper = new Wrapper();
         ChatServer chatServer = null;
         
         public void run()
         {
            try
            {
                = .join(chatInfo.get_key(), newMember);
            }
            catch (ShuttingDownException sde)
            {
               SwingUtilities.invokeLater();
            }
            catch (RemoteConnectionException e)
            {
               .error("Cannot join chat room: " + chatInfo.get_description());
               .error(e);
            }
            catch (NameInUseException niue)
            {
               ..println("Pick a new name");
            }
            Runnable r = new Runnable()
            {
               public void run()
               {
                  .registerStrategy(new TalkConnectionStrategyImpl(newMember));
                  .registerChatKey(chatInfo.get_key());
                  .show();
               }
            };
            SwingUtilities.invokeLater(r);
         }
      };
      t.start();
   }
   
   // ****************************************************************
   // InfoConnectionStrategy + ListConnectionStrategy
   public void getId(ChatInfo chatInfo)
   {
       = new JoinFrame(chatInfothis);
      .show();
   }
   public void getInfo(ArrayList chatInfoListint keythrows ListConnectionException
   {
       = new InfoFrame(this, (ChatInfochatInfoList.get(key), );
      .show();
   }
   
   // ****************************************************************
   // TalkConnectionStrategy
   {
      private ChatServer chatServer;
      private ChatMember member;
      private ReadWriteArrayList outgoingLines;
      public TalkConnectionStrategyImpl(ChatMember memberChatServer csReadWriteArrayList outgoingLines)
      {
          = cs;
         this. = member;
         this. = outgoingLines;
      }
      // getBackChat() is not currently used, since the ChatReceiverThread created by ChatManager_Impl
      // sends all existing lines in the chat room, starting with line 0.
      //      public void getBackChat(final TalkFrame talkFrame)
      //      {
      //        Thread t = new Thread() {
      //          public void run() {
      //            try {
      //              String[] backChat =  remoteChatServer.getBackChat();
      //              if (backChat == null)
      //                backChat = new String[0];
      //              talkFrame.setBackChat(backChat);
      //            }
      //            catch (ShuttingDownException sde) {
      //              SwingUtilities.invokeLater(shuttingDownDialogRunnable);
      //            }
      //            catch (RemoteConnectionException rce) {
      //              System.out.println("TalkConnectionStrategy: unable to get back chat");
      //              System.out.println(rce);
      //            }
      //          }
      //        };
      //
      //        t.start();
      //      }
      public void send(ChatMessage messagethrows TalkConnectionException
      {
         .add(message);
      }
      public void leave()
      {
         Thread t = new Thread()
         {
            public void run()
            {
               try
               {
                  .leave();
               }
               catch (ShuttingDownException sde)
               {
                  SwingUtilities.invokeLater();
               }
               catch (RemoteConnectionException e)
               {
                  .error("TalkConnectionStrategy.leave(): unable to leave chat room");
                  .error(e);
               }
                = null;
            }
         };
         t.start();
      }
   }
   // ****************************************************************
   public void notifyOnClose(Component c)
   {
      c.setVisible(false);
   }
   protected boolean isChatting()
   {
      return ;
   }
   protected void setIsChatting(boolean b)
   {
       = b;
   }
   // ****************************************************************
   {
      public void run()
      {
         .show();
      }
   };
New to GrepCode? Check out our FAQ X