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

📄 instantmessaginggui.java

📁 基于JAINSIP的一个proxy源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * IMGUI.java * * Created on July 27, 2002, 10:57 PM */package gov.nist.sip.instantmessaging;import javax.sip.*;import javax.sip.message.*; import javax.sip.header.*;import javax.sip.address.*;import javax.swing.*;import javax.swing.border.*;import java.awt.*;import java.awt.event.*;import java.net.*;import java.util.*;import java.io.*;import gov.nist.sip.instantmessaging.presence.*;import gov.nist.sip.instantmessaging.authentication.* ;/** * * @author  olivier * @version 1.0 */public class InstantMessagingGUI extends JFrame {    // Menus    protected JMenuBar menuBar;    protected JMenu menuMenu;    protected JMenu statusMenu;    protected JMenu optionsMenu;    protected JMenu signMenu;    protected JMenu helpMenu;    protected JMenu quit;    protected JMenuItem configurationMenuItem;    protected JMenuItem connectionMenuItem;    protected JMenuItem debugMenuItem;        protected JMenuItem sendIMMenuItem;    protected JMenuItem addContactMenuItem;    protected JMenuItem removeContactMenuItem;    protected JRadioButtonMenuItem onlineJRadioButtonMenuItem;    protected JRadioButtonMenuItem awayJRadioButtonMenuItem;    protected JRadioButtonMenuItem offlineJRadioButtonMenuItem;    protected JRadioButtonMenuItem busyJRadioButtonMenuItem;    protected JMenuItem tracesViewerMenuItem;        protected JPanel firstPanel;    protected JPanel secondPanel;    protected JLabel localSipURLLabel;    protected JLabel statusLabel;    protected JTextField localSipURLTextField;    protected JLabel buddyLabel;    protected BuddyList buddyList;        private AuthenticationProcess authenticationProcess;    protected ListenerInstantMessaging listenerInstantMessaging;    protected IMUserAgent instantMessagingUserAgent;       // All for the container:    protected static Color containerBackGroundColor=new Color(204,204,204);    protected static String logo="logoNist-gray.jpg";        // All for the labels:    protected static Border labelBorder=new EtchedBorder(EtchedBorder.RAISED);    protected static Color labelBackGroundColor=new Color(217,221,221);        // All for the TextField    protected static Color textBackGroundColor=Color.white;        // All for the Button    protected static Border buttonBorder=new BevelBorder(BevelBorder.RAISED);    protected static Color  buttonBackGroundColor=new Color(186,175,175);        protected String propertiesFile;    protected Properties properties;    protected String xmlBuddiesFile;/******************************************************************************/   /*********************************  Some useful methods ***********************/    /******************************************************************************/        protected String replaceSlashByBackSlash(String line) {        if (line==null) return null;        else {            try{                StringBuffer res=new StringBuffer();                for (int i=0;i<line.length();i++) {                    char c=line.charAt(i);                    if ( c=='\\' )                        res.append("/");                    else res.append(c);                }                //DebugIM.println("Utils:"+res);                return res.toString();            }            catch(Exception e) {                return null;            }        }    }            public AuthenticationProcess getAuthenticationProcess() {        return authenticationProcess;    }            public boolean getAuthorizationForBuddy(String buddy) {        // WE should read in a file for the old subscriptions        // if it's accepted and rejected                // Let's check if we have an already defined authorization for this buddy:                if (buddyList.hasAuthorization(buddy)) {            DebugIM.println("DEBUG, InstantMessagingGUI, getAuthorizationForBuddy()"+            ", we got a positive authorization from the XML file for: "+buddy);            return true;        }        else {                     DebugIM.println("DEBUG, InstantMessagingGUI, getAuthorizationForBuddy()"+            ", the user has to authorize the buddy to subscribe: "+buddy);            AlertInstantMessaging alertInstantMessaging= new            AlertInstantMessaging("The buddy "+            buddy+" wants to add you in his buddy list, do you authorize him?",            AlertInstantMessaging.CONFIRMATION,null);                        boolean author=(alertInstantMessaging.getConfirmationResult()==JOptionPane.OK_OPTION);            // WE have to update the buddies vector!!!           // buddyList.setAuthorization(buddy,author);             DebugIM.println("DEBUG, InstantMessagingGUI, getAuthorizationForBuddy()"+            ", the user authorization is: "+author);            return author;        }    }        public BuddyList getBuddyList() {        return buddyList;    }        public JMenu getSignMenu() {        return signMenu;    }        public JRadioButtonMenuItem getOfflineJRadioButtonMenuItem() {        return offlineJRadioButtonMenuItem;    }        public JRadioButtonMenuItem getOnlineJRadioButtonMenuItem() {        return onlineJRadioButtonMenuItem;    }        public JLabel getStatusLabel() {        return statusLabel;    }               public String getPropertiesFile() {        return propertiesFile;    }         public JTextField getLocalSipURLTextField() {        return localSipURLTextField;    }        public IMUserAgent getInstantMessagingUserAgent() {        return instantMessagingUserAgent;    }        public ListenerInstantMessaging getListenerInstantMessaging() {        return listenerInstantMessaging;    }    public String getXMLBuddiesFile() {        return xmlBuddiesFile;    }        public void start() {        try{            instantMessagingUserAgent.start();                   }        catch(Exception e) {            DebugIM.println("DebugIM, InstantMessagingGUI, start(), Unable to start the UA:");            e.printStackTrace();        }    }        public void stop() {        try{            instantMessagingUserAgent.stop();                   }        catch(Exception e) {            DebugIM.println("DebugIM, InstantMessagingGUI, stop(), Unable to stop the UA:");            e.printStackTrace();        }    }        public void restart() {        try{            DebugIM.println("\n***************** RESTARTING ****************************\n");            stop();            uploadProperties(propertiesFile);            initFields();            uploadBuddies();            uploadAuthentication();            start();            if (listenerInstantMessaging.tracesViewer!=null) {                try{                 listenerInstantMessaging.tracesViewer.close();                 listenerInstantMessaging.tracesViewer=null;                 //listenerInstantMessaging.tracesViewerActionPerformed(null);                 DebugIM.println("DebugIM, restart(), traces viewer closed.");                }                catch(Exception e) {                    DebugIM.println("DebugIM, InstantMessagingGUI, restart(), traces viewer"+                    " not closed, exception raised:");                    e.printStackTrace();                }            }                   DebugIM.println("\n*************************************************\n");        }        catch(Exception e) {            DebugIM.println("DebugIM, InstantMessagingGUI, restart(), Unable to restart the UA:");            e.printStackTrace();        }    }        public void blockProperties() {        localSipURLTextField.setEditable(false);        localSipURLTextField.setBackground(Color.lightGray);        ConfigurationFrame configurationFrame=listenerInstantMessaging.getConfigurationFrame();        configurationFrame.blockProperties();    }        public void unblockProperties() {        localSipURLTextField.setEditable(true);        localSipURLTextField.setBackground(Color.white);        ConfigurationFrame configurationFrame=listenerInstantMessaging.getConfigurationFrame();        configurationFrame.unblockProperties();    }        public void uploadProperties(String propertiesFile) {        properties=new Properties();                if (propertiesFile==null) {            DebugIM.println("DebugIM, Unable to upload the properties: properties file missing");            return;        }                        DebugIM.println("DebugIM, InstantMessagingGUI, we upload the properties from the "+        "file:"+propertiesFile);        try{            properties.load( new FileInputStream(propertiesFile)) ;            DebugIM.println("DebugIM, InstantMessagingGUI, properties uploaded.");        }        catch(Exception e) {            DebugIM.println("DebugIM, InstantMessagingGUI, properties file not found");        }    }    public void initFields() {        String localSipURL=properties.getProperty("examples.im.localSipURL");        if (localSipURL!=null) {            if (localSipURL.startsWith("sip:"))                   localSipURLTextField.setText(localSipURL);            else localSipURLTextField.setText("sip:"+localSipURL);        }        else   DebugIM.println("DebugIM, InstantMessagingGUI, initFields(),"+             " Local Sip URL not set!!");                        ConfigurationFrame configurationFrame=listenerInstantMessaging.getConfigurationFrame();                        // Init the components input:        String outboundProxyAddress=properties.getProperty("examples.im.outboundProxyAddress");        if (outboundProxyAddress!=null && !outboundProxyAddress.trim().equals(""))             configurationFrame.outboundProxyAddressTextField.setText(outboundProxyAddress);        String outboundProxyPort=properties.getProperty("examples.im.outboundProxyPort");        if (outboundProxyPort!=null && !outboundProxyPort.trim().equals(""))             configurationFrame.outboundProxyPortTextField.setText(outboundProxyPort);                String registrarAddress=properties.getProperty("examples.im.registrarAddress");        if ( registrarAddress!=null && !registrarAddress.trim().equals(""))             configurationFrame.registrarAddressTextField.setText(registrarAddress);        String registrarPort=properties.getProperty("examples.im.registrarPort");        if (registrarPort!=null && !registrarPort.trim().equals("") )            configurationFrame.registrarPortTextField.setText(registrarPort);                String imAddress=properties.getProperty("examples.im.imAddress");        if ( imAddress!=null && !imAddress.trim().equals(""))            configurationFrame.imAddressTextField.setText(imAddress);        String imPort=properties.getProperty("examples.im.imPort");        if (imPort!=null && !imPort.trim().equals(""))            configurationFrame.imPortTextField.setText(imPort);        String imProtocol=properties.getProperty("examples.im.imProtocol");        if (imProtocol!=null && !imProtocol.trim().equals(""))            configurationFrame.imProtocolTextField.setText(imProtocol);                String outputFile=properties.getProperty("examples.im.outputFile");        if (outputFile!=null && !outputFile.trim().equals("")) {            configurationFrame.outputFileTextField.setText(outputFile);            DebugIM.setDebugFile(outputFile);        }                                String buddiesFile=properties.getProperty("examples.im.buddiesFile");        if (  buddiesFile!=null && !buddiesFile.trim().equals(""))             configurationFrame.buddiesFileTextField.setText(buddiesFile);        String authenticationFile=properties.getProperty("examples.im.authenticationFile");        if (  authenticationFile!=null && !authenticationFile.trim().equals(""))             configurationFrame.authenticationFileTextField.setText(authenticationFile);                String router=properties.getProperty("examples.im.defaultRouter");        if (router!=null && !router.trim().equals(""))            configurationFrame.defaultRouterTextField.setText(router);            }        public void uploadBuddies() {            xmlBuddiesFile=properties.getProperty("examples.im.buddiesFile");            if (xmlBuddiesFile!=null) {                                XMLBuddyParser xmlBuddyParser=new XMLBuddyParser(xmlBuddiesFile);                Vector buddies=xmlBuddyParser.getBuddies();                if (buddies!=null)                    buddyList.init(buddies);                else {                    DebugIM.println("DebugIM, InstantMessagingGUI, uploadBuddies(),"+                    " No Buddies to upload...");                    buddyList.init(new Vector());                }            }            else  {                DebugIM.println("DebugIM, InstantMessagingGUI, uploadBuddies(),"+                " Property not set for uploading the buddies...");                buddyList.init(new Vector());            }    }        public void uploadAuthentication() {        try{                        String authenticationFile=properties.getProperty("examples.im.authenticationFile");            if (authenticationFile!=null && !authenticationFile.trim().equals("")) {                                XMLAuthenticationParser xmlAuthenticationParser=                new XMLAuthenticationParser(authenticationFile);                Vector usersTagList=xmlAuthenticationParser.getUsersTagList();                                authenticationProcess=new AuthenticationProcess(instantMessagingUserAgent,usersTagList);            }            else {                DebugIM.println("DebugIM, InstantMessagingGUI, uploadAuthentication(),"+                " the file for authentication is missing");            }        }        catch(Exception e) {            DebugIM.println("DebugIM, InstantMessagingGUI, uploadAuthentication(),"+                " Error trying to upload the authentication file ");            e.printStackTrace();        }

⌨️ 快捷键说明

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