shalbert     Design

Hal Danger · United States · male · 28 years old · registered since 1998 · last online - 4 days ago

ChatManager class

Other ·

package com.shalsoft.chatfoo;

import java.util.ArrayList;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class ChatManager {
   private ArrayList<Channel> ChannelList = new ArrayList<Channel>();
   private ArrayList<Dialog> DialogList = new ArrayList<Dialog>();
   private Shell theShell;
   private CTabFolder theCTabFolder;
   
   public ChatManager(Shell parent, CTabFolder thistabfolder) {
      theShell = parent;
      theCTabFolder = thistabfolder;
   }
   
   public void addDialog(String someuser){
      Dialog myDialog = new Dialog(theShell, this, theCTabFolder, someuser);
      myDialog.open();
      DialogList.add(myDialog);
      
   }
   
   public void addChannel(String somechannel) {
        Channel myChannel = new Channel(theShell, this, theCTabFolder, somechannel);
        myChannel.open();
        ChannelList.add(myChannel);
   }
   
   public boolean removeChannel(String somechannel){
      boolean foundchannel = false;
      for(int i=0;i < ChannelList.size();i++)
      {
         Channel tmpchannel = ChannelList.get(i);
         if (tmpchannel.getChannelName().equals(somechannel)){
            System.out.println("remove channel " + somechannel + "##");
            ChannelList.remove(i);
            tmpchannel.getTabItem().dispose();
            foundchannel = true;
         }
      }
      
      return foundchannel;
   }
   
   public boolean removeDialog(String someuser){
      boolean founduser = false;
      for(int i=0;i < DialogList.size();i++)
      {
         Dialog tmpdialog = DialogList.get(i);
         if (tmpdialog.getUserName().equals(someuser)){
   
            DialogList.remove(i);
            tmpdialog.getTabItem().dispose();
            founduser = true;
         }
      }
      
      return founduser;
   }
   
   public Channel getChannel(String somechannel){
      Channel tmpchannel = null;
      for(int i=0;i < ChannelList.size();i++)
      {

         if (ChannelList.get(i).getChannelName().equals(somechannel)){
            tmpchannel = ChannelList.get(i);
         }
      }
      return tmpchannel;
   }
   
   public Dialog getDialog(String someuser){
      Dialog tmpdialog = null;
      for(int i=0;i < DialogList.size();i++)
      {

         if (DialogList.get(i).getUserName().equals(someuser)){
            tmpdialog = DialogList.get(i);
         }
      }
      return tmpdialog;
   }
   
   public String getAllChannels(){
      String allchannels = "";
      for(int i=0;i < ChannelList.size();i++)
      {
         if (allchannels.equals("")){
            allchannels = ChannelList.get(i).getChannelName(); 
         }else{
            allchannels = allchannels + ", " + ChannelList.get(i).getChannelName(); 
         }
      }
      
      return allchannels;
   }
   
   public void removeAllChannels(){
      ArrayList<Channel> TempChannelList = new ArrayList<Channel>(ChannelList);
      
      for(int i=0;i < TempChannelList.size();i++)
      {
            Channel tmpchannel = TempChannelList.get(i);
            tmpchannel.getTabItem().dispose();
      }
      System.out.println("All Channels: " + getAllChannels());
      ChannelList.clear();
      
   }
   
   public String getAllDialogs(){
      String alldialogs = "";
      ArrayList<Dialog> TempDialList = new ArrayList<Dialog>(DialogList);
      for(int i=0;i < TempDialList.size();i++)
      {
         if (alldialogs.equals("")){
            alldialogs = TempDialList.get(i).getUserName(); 
         }else{
            alldialogs = alldialogs + ", " + TempDialList.get(i).getUserName(); 
         }
      }
      
      return alldialogs;
   }
   
   public void removeAllDialogs(){
      for(int i=0;i < DialogList.size();i++)
      {
         Dialog tmpdialog = DialogList.get(i);
         tmpdialog.getTabItem().dispose();
      }
      DialogList.clear();
   }
   
   public boolean channelAlreadyOpen(String somechannel) {
      boolean foundchannel = false;
      for(int i=0;i < ChannelList.size();i++)
      {
         Channel tmpchannel = ChannelList.get(i);
         if (tmpchannel.getChannelName().equals(somechannel)){
            foundchannel = true;
         }
      }      
      return foundchannel;
   }
   
   public boolean dialogAlreadyOpen(String someuser) {
      boolean founddialog = false;
      for(int i=0;i < DialogList.size();i++)
      {
         Dialog tmpdialog = DialogList.get(i);
         if (tmpdialog.getUserName().equals(someuser)){
            founddialog = true;
         }
      }      
      return founddialog;
   }


   

}
November 29th, 2011 23:30

Tags:  ·  ·  ·  ·  ·

I client's timer thread - I only have one, and I use mod operator to trigger other events.

Computer ·

      public void startTimerThread() {
         new Thread() {
            public void run(){
               try {   
                  mytimerThread = Thread.currentThread();
                  int tc = 0;
                  int myPingTimer = 10;
                  int msgTimer = 30;
                  int netStatsTimer = 3;
                  while(!(Thread.currentThread().isInterrupted())){
                     Thread.sleep(1000);
                     tc++;
                     if (tc % myPingTimer == 0){
                        send("Jp");
                        responsetime = new Date().getTime();
                     }
                     if (tc % msgTimer == 0){
                        thedisplay.asyncExec(
                              new Runnable() {
                                     public void run(){
                                       try {
                                         try {
                                            ChatFoo.loadMsgInfo(mywebhelper.getMsgInfo());
                                         } catch (ParseException e) {
                                            e.printStackTrace();
                                         }
                                    } catch (IOException e) {
                                       e.printStackTrace();
                                    }
                                }
                          });
                     }
                     if (tc % netStatsTimer == 0){
                        thedisplay.asyncExec(
                                 new Runnable() {
                                        public void run(){
                                          ChatFoo.updateDataIn("Data in: " + datain + " bytes");
                                          ChatFoo.updateDataOut("Data out: " + dataout + " bytes");
                                   }
                             });
                     }
                  }
               } catch (IOException e) {
                  e.printStackTrace();
               } catch (InterruptedException e) {
                  //e.printStackTrace();
               }
            }
         }.start();   
      }   
}
November 23rd, 2011 17:07

Tags:  ·  ·  ·  ·

Show entries

Year 2012 (1)
 
Year 2011 (3)
  November (2)
  April (1)
 
Year 2010 (1)
Year 2008 (5)

Subscribe

RSS 2.0

Search blog
(only public entries)

Do you want to blog, too?
Blog for free at spinchat.com
This page is a personal homepage hosted on spinchat.com. The responsibility lies with the user.
spinchat.com is a large online-community with chat, blogs, boards, online games and much more.
Spinchat.com: meet new friends

Imprint · Privacy policy · Sitemap