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

📄 settingspanel.java

📁 java 开发的sip软电话 源码 jain sip
💻 JAVA
字号:
package net.java.mais.media.jmf;

/**
 * <p>Title: SIP Communicator</p>
 *
 * <p>Description: A SIP UA</p>
 *
 * <p>Copyright: Copyright (c) 2004</p>
 *
 * <p>Company: Network Research Team, Louis Pasteur University</p>
 *
 * @author Emil Ivov
 * @version 1.0
 */
/*
 * @(#)SettingsPanel.java	1.6 02/08/21
 *
 * Copyright (c) 1996-2002 Sun Microsystems, Inc.  All rights reserved.
 */

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.sun.media.util.JMFI18N;
import com.sun.media.util.Registry;

import jmapps.ui.MessageDialog;


public class SettingsPanel extends JMPanel implements ActionListener {

    private JCheckBox    checkAllowCaching;
    // private TextField   textAllowFileRead;
    private JCheckBox    checkAllowFileWrite;
    private JCheckBox    checkAllowCapture;
    private JTextField   textMaxCacheSize;
    private JTextField   textCacheDir;
    private JCheckBox    checkAllowLogging;
    private JTextField   textLoggingDir;

    private JButton      buttonCommit;
    private JButton      buttonRestore;


    public SettingsPanel() {
        JPanel   panel;
        JPanel   panelButtons;
        JPanel   panelData;
        JPanel   panelEntry;
        JLabel   label;

        setLayout( new BorderLayout(6,6) );

        panel = new JPanel ( new BorderLayout(6,6) );
        this.add ( panel, BorderLayout.NORTH );
        panelData = new JPanel ( new GridLayout(0,1,6,6) );
        panel.add ( panelData, BorderLayout.WEST );


//         panelEntry = new JPanel ( new BorderLayout(6,6) );
//         panelData.add ( panelEntry );
//         label = new JLabel ( JMFI18N.getResource("jmfregistry.settings.allowfileread") );
//         panelEntry.add ( label, BorderLayout.WEST );
//         textAllowFileRead = new TextField ( 32 );
//         panelEntry.add ( textAllowFileRead, BorderLayout.CENTER );

        panelEntry = new JPanel ( new BorderLayout(6,6) );
        panelData.add ( panelEntry );
        checkAllowFileWrite = new JCheckBox ( JMFI18N.getResource("jmfregistry.settings.allowfilewrite") );
        panelEntry.add ( checkAllowFileWrite, BorderLayout.WEST );

        panelEntry = new JPanel ( new BorderLayout(6,6) );
        panelData.add ( panelEntry );
        checkAllowCapture = new JCheckBox ( JMFI18N.getResource("jmfregistry.settings.allowcapture") );
        panelEntry.add ( checkAllowCapture, BorderLayout.WEST );

        panelEntry = new JPanel ( new BorderLayout(6,6) );
        panelData.add ( panelEntry );
        checkAllowCaching = new JCheckBox ( JMFI18N.getResource("jmfregistry.settings.allowcaching") );
        panelEntry.add ( checkAllowCaching, BorderLayout.WEST );

        panelEntry = new JPanel ( new BorderLayout(6,6) );
        panelData.add ( panelEntry );
        label = new JLabel ( JMFI18N.getResource("jmfregistry.settings.cachedirectory") );
        panelEntry.add ( label, BorderLayout.WEST );
        textCacheDir = new JTextField ( 32 );
        panelEntry.add ( textCacheDir, BorderLayout.CENTER );

        panelEntry = new JPanel ( new BorderLayout(6,6) );
        panelData.add ( panelEntry );
        label = new JLabel ( JMFI18N.getResource("jmfregistry.settings.maxcache") );
        panelEntry.add ( label, BorderLayout.WEST );
        textMaxCacheSize = new JTextField ();
        panelEntry.add ( textMaxCacheSize, BorderLayout.CENTER );

        panelEntry = new JPanel ( new BorderLayout(6,6) );
        panelData.add ( panelEntry );
        checkAllowLogging = new JCheckBox ( JMFI18N.getResource("jmfregistry.settings.allowlogging") );
        panelEntry.add ( checkAllowLogging, BorderLayout.WEST );

        panelEntry = new JPanel ( new BorderLayout(6,6) );
        panelData.add ( panelEntry );
        label = new JLabel ( JMFI18N.getResource("jmfregistry.settings.loggingdirectory") );
        panelEntry.add ( label, BorderLayout.WEST );
        textLoggingDir = new JTextField ();
        panelEntry.add ( textLoggingDir, BorderLayout.CENTER );

        panel = new JPanel ( new FlowLayout(FlowLayout.CENTER) );
        this.add ( panel, BorderLayout.SOUTH );
        panelButtons = new JPanel ( new GridLayout(1,0,12,12) );
        panel.add ( panelButtons );

        buttonCommit = new JButton ( JMFI18N.getResource("jmfregistry.settings.commit") );
        buttonCommit.addActionListener( this );
        panelButtons.add ( buttonCommit );

        buttonRestore = new JButton ( JMFI18N.getResource("jmfregistry.settings.restore") );
        buttonRestore.addActionListener( this );
        panelButtons.add ( buttonRestore );

        doRestore();
    }

    public void actionPerformed(ActionEvent ae) {
        Object source = ae.getSource();
        if (source == buttonCommit)
            doCommit();
        if (source == buttonRestore)
            doRestore();
    }

    private void doCommit() {
        boolean allowCaching = checkAllowCaching.isSelected();
        Registry.set("secure.allowCaching", new Boolean(allowCaching));
        boolean allowFileWrite = checkAllowFileWrite.isSelected();
        Registry.set("secure.allowSaveFileFromApplets", new Boolean(allowFileWrite));
        boolean allowCapture = checkAllowCapture.isSelected();
        Registry.set("secure.allowCaptureFromApplets", new Boolean(allowCapture));

        Registry.set("secure.cacheDir", textCacheDir.getText());
    // Registry.set("secure.additionalFileExtensions", textAllowFileRead.getText());

        boolean allowLogging = checkAllowLogging.isSelected();
        Registry.set("allowLogging", new Boolean(allowLogging));
        Registry.set("secure.logDir", textLoggingDir.getText());

        try {
            int cacheSize = Integer.parseInt(textMaxCacheSize.getText());
            Registry.set("secure.maxCacheSizeMB", new Integer(cacheSize));
        }
        catch (Throwable t) {
            MessageDialog.createErrorDialog ( getFrame(),
                                JMFI18N.getResource("jmfregistry.appname"),
                                JMFI18N.getResource("jmfregistry.error.cachesize") );
        }

        try {
            Registry.commit();
        }
        catch (IOException ioe) {
            MessageDialog.createErrorDialog ( getFrame(),
                                JMFI18N.getResource("jmfregistry.appname"),
                                JMFI18N.getResource("jmfregistry.error.commit") );
        }
    }

    private void doRestore() {
        Boolean allowCaching = (Boolean) Registry.get("secure.allowCaching");
        Boolean allowFile = (Boolean) Registry.get("secure.allowSaveFileFromApplets");
        Boolean allowCapture = (Boolean) Registry.get("secure.allowCaptureFromApplets");
        String  cacheDir = (String) Registry.get("secure.cacheDir");
        Integer cacheSize = (Integer) Registry.get("secure.maxCacheSizeMB");
        Boolean allowLogging = (Boolean) Registry.get("allowLogging");
        String  loggingDir = (String) Registry.get("secure.logDir");

        // String  fileExtensions = (String) Registry.get("secure.additionalFileExtensions");

        checkAllowCaching.setSelected ( (allowCaching != null  &&  ((Boolean)allowCaching).booleanValue()) );
        checkAllowFileWrite.setSelected ( (allowFile != null  &&  ((Boolean)allowFile).booleanValue()) );
        checkAllowCapture.setSelected ( (allowCapture != null  &&  ((Boolean)allowCapture).booleanValue()) );
        checkAllowLogging.setSelected ( (allowLogging != null  &&  ((Boolean)allowLogging).booleanValue()) );
        if (cacheDir != null)
            textCacheDir.setText(cacheDir);
        if (cacheSize != null)
            textMaxCacheSize.setText(cacheSize.toString());
//         if (fileExtensions != null)
//             textAllowFileRead.setText(fileExtensions);
        if (loggingDir != null)
            textLoggingDir.setText(loggingDir);
    }

}


⌨️ 快捷键说明

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