⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 listenerinstantmessaging.java

📁 The source code for this package is located in src/gov/nist/sip/proxy. The proxy is a pure JAIN-SIP
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
          //  }          //  else  new AlertInstantMessaging(          //  "You must sign in first to the server!!!",JOptionPane.ERROR_MESSAGE);        }        catch(Exception e) {            e.printStackTrace();        }       }        public void addContact(String contact){        try{                        IMUserAgent imUA=imGUI.getInstantMessagingUserAgent();            IMRegisterProcessing imRegisterProcessing=imUA.getIMRegisterProcessing();            IMSubscribeProcessing imSubscribeProcessing=imUA.getIMSubscribeProcessing();           // if (imRegisterProcessing.isRegistered()) {                AlertInstantMessaging alert=new AlertInstantMessaging("Do you want to add "+                contact+" to your buddy list?",                AlertInstantMessaging.CONFIRMATION,null);                if (alert.getConfirmationResult()==JOptionPane.OK_OPTION){                    // WE have to send a SUBSCRIBE!!!                    imSubscribeProcessing.sendSubscribe(getLocalSipURL(),contact,false);                }           // }           // else  new AlertInstantMessaging(           // "You must sign in first to the server!!!",JOptionPane.ERROR_MESSAGE);        }        catch(Exception e) {            DebugIM.println("ERROR, ListenerInstantMessaging, addContact(), buddy is null:");            e.printStackTrace();        }    }        public void addContactActionPerformed(ActionEvent evt){        IMUserAgent imUA=imGUI.getInstantMessagingUserAgent();        IMRegisterProcessing imRegisterProcessing=imUA.getIMRegisterProcessing();        IMSubscribeProcessing imSubscribeProcessing=imUA.getIMSubscribeProcessing();        if (imRegisterProcessing.isRegistered()) {            AlertInstantMessaging alert=new AlertInstantMessaging("Enter the URI"+            " of the buddy to add:",            JOptionPane.INFORMATION_MESSAGE,"sip:");            if (alert.finalInputValue!=null){                String buddy=alert.finalInputValue;                if (buddy==null || !XMLBuddyParser.checkURI(buddy) ) {                    new AlertInstantMessaging("The URI is not valid: enter sip:....",                    JOptionPane.ERROR_MESSAGE);                }                else {                    // WE have to check if the contact is not already in the buddy list:                    // WE have to create a new Buddy in the GUI!!!                                        BuddyList buddyList=imGUI.getBuddyList();                    if ( !buddyList.hasBuddy(buddy) ) {                         // WE have to send a SUBSCRIBE!!! WE will add the buddy                         // when we will receive the OK...                           DebugIM.println("DEBUG, ListenerInstantMessaging, "+                        " addContactActionPerformed(), WE are going to send a SUBSCRIBE...");                        imSubscribeProcessing.sendSubscribe(getLocalSipURL(),buddy,false);                    }                    else {                        DebugIM.println("DEBUG, ListenerInstantMessaging, "+                        " addContactActionPerformed(), The buddy is already in the Buddy list...");                    }                }            }        }        else  new AlertInstantMessaging(        "You must sign in first to the server!!!",JOptionPane.ERROR_MESSAGE);    }        public void removeContactActionPerformed(ActionEvent evt){        IMUserAgent imUA=imGUI.getInstantMessagingUserAgent();        IMRegisterProcessing imRegisterProcessing=imUA.getIMRegisterProcessing();        if (imRegisterProcessing.isRegistered()) {            // Just to make sure u know :-)            AlertInstantMessaging alertInstantMessaging=            new AlertInstantMessaging("Are you sure to remove the selected contact?",            AlertInstantMessaging.CONFIRMATION,            null);            int confirmationResult=alertInstantMessaging.getConfirmationResult();            if (confirmationResult==JOptionPane.YES_OPTION) {                BuddyList buddyList=imGUI.getBuddyList();                                String buddy=buddyList.getBuddy(buddyList.getSelectedIndex());                if (buddy!=null) {                    if (imRegisterProcessing.isRegistered()) {                    IMSubscribeProcessing imSubscribeProcessing=imUA.getIMSubscribeProcessing();                    // WE have to send a "unSUBSCRIBE"!!!                    DebugIM.println("DEBUG, ListenerInstantMessaging, "+                    " removeContactActionPerformed(), We have to unSUBSCRIBE to the buddy: "+buddy);                    imSubscribeProcessing.sendSubscribe(getLocalSipURL(),buddy,true);                                        }                    buddyList.removeSelectedBuddy();                }                else {                    new AlertInstantMessaging("You must select a contact to remove!",                    JOptionPane.ERROR_MESSAGE);                }            }        }       else  new AlertInstantMessaging(        "You must sign in first to the server!!!",JOptionPane.ERROR_MESSAGE);    }        public void onlineActionPerformed(ActionEvent evt){        IMUserAgent imUA=imGUI.getInstantMessagingUserAgent();        IMRegisterProcessing imRegisterProcessing=imUA.getIMRegisterProcessing();        if (imRegisterProcessing.isRegistered()) {            JLabel statusLabel=imGUI.getStatusLabel();            statusLabel.setText("You are: ONLINE");                       localStatus="online";                        // we have to notify our SUBSCRIBERS: let's send a NOTIFY for each            // of them:            IMNotifyProcessing imNotifyProcessing=imUA.getIMNotifyProcessing();            imNotifyProcessing.sendNotifyToAllSubscribers("open",localStatus);        }        else  new AlertInstantMessaging(        "You must sign in first to the server!!!",JOptionPane.ERROR_MESSAGE);    }        public void offlineActionPerformed(ActionEvent evt){        IMUserAgent imUA=imGUI.getInstantMessagingUserAgent();        IMRegisterProcessing imRegisterProcessing=imUA.getIMRegisterProcessing();        if (imRegisterProcessing.isRegistered()) {            JLabel statusLabel=imGUI.getStatusLabel();            statusLabel.setText("You are: OFFLINE");                        localStatus="offline";                        // we have to notify our SUBSCRIBERS: let's send a NOTIFY for each            // of them:            IMNotifyProcessing imNotifyProcessing=imUA.getIMNotifyProcessing();            imNotifyProcessing.sendNotifyToAllSubscribers("closed",localStatus);        }        else  new AlertInstantMessaging(        "You must sign in first to the server!!!",JOptionPane.ERROR_MESSAGE);    }        public void busyActionPerformed(ActionEvent evt){        IMUserAgent imUA=imGUI.getInstantMessagingUserAgent();        IMRegisterProcessing imRegisterProcessing=imUA.getIMRegisterProcessing();        if (imRegisterProcessing.isRegistered()) {            JLabel statusLabel=imGUI.getStatusLabel();            statusLabel.setText("You are: BUSY");                        localStatus="busy";                        // we have to notify our SUBSCRIBERS: let's send a NOTIFY for each            // of them:            IMNotifyProcessing imNotifyProcessing=imUA.getIMNotifyProcessing();            imNotifyProcessing.sendNotifyToAllSubscribers("open",localStatus);        }        else  new AlertInstantMessaging(        "You must sign in first to the server!!!",JOptionPane.ERROR_MESSAGE);    }        public void awayActionPerformed(ActionEvent evt){        IMUserAgent imUA=imGUI.getInstantMessagingUserAgent();        IMRegisterProcessing imRegisterProcessing=imUA.getIMRegisterProcessing();        if (imRegisterProcessing.isRegistered()) {            JLabel statusLabel=imGUI.getStatusLabel();            statusLabel.setText("You are: AWAY");                        localStatus="away";                        // we have to notify our SUBSCRIBERS: let's send a NOTIFY for each            // of them:            IMNotifyProcessing imNotifyProcessing=imUA.getIMNotifyProcessing();            imNotifyProcessing.sendNotifyToAllSubscribers("open",localStatus);        }        else  new AlertInstantMessaging(        "You must sign in first to the server!!!",JOptionPane.ERROR_MESSAGE);    }                public String getLocalSipURL() {        try{            JTextField localSipURLTextField=imGUI.getLocalSipURLTextField();            String text=localSipURLTextField.getText();             if (text==null || text.trim().equals("") || text.trim().equals("sip:") ) {                new AlertInstantMessaging("You must enter your sip url before signing in!!!",                JOptionPane.ERROR_MESSAGE);                return null;            }            else {               if (text.startsWith("sip:")) {                     return text;                }                 else {                    String res="sip:"+text;                    return res;                }            }        }        catch(Exception e) {            e.printStackTrace();            return null;        }            }      public void signMenuMouseClicked(MouseEvent mouseEvent) {        try{           IMUserAgent instantMessagingUserAgent=imGUI.getInstantMessagingUserAgent();            // Send a REGISTER to the proxy            // and wait for the OK.            String localSipURL=getLocalSipURL();            if (localSipURL!=null && !localSipURL.trim().equals("") ) {                // Build the message:                IMUserAgent imUA=imGUI.getInstantMessagingUserAgent();                IMRegisterProcessing imRegisterProcessing=imUA.getIMRegisterProcessing();		IMPublishProcessing imPublishProcessing=imUA.getIMPublishProcessing();                if (imRegisterProcessing.isRegistered()) {                    //It means we will sign out!!!		    imPublishProcessing.sendPublish(localSipURL.trim(),"offline");                    imRegisterProcessing.signOut(localSipURL.trim());                }                else {                    imRegisterProcessing.signIn(localSipURL.trim());                }            }        }        catch(Exception e) {            e.printStackTrace();        }    }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -