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

📄 optionspanel.java

📁 java语言开发的P2P流媒体系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* Stream-2-Stream - Peer to peer television and radio
 * Project homepage: http://s2s.sourceforge.net/
 * Copyright (C) 2005-2006 Jason Hooks
 * ---------------------------------------------------------------------------
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * ---------------------------------------------------------------------------
 */

package p2pradio.gui;

import p2pradio.logging.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.security.NoSuchAlgorithmException;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Set;
import java.util.TreeMap;
import java.util.logging.Filter;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;

import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.swing.*;

import ndt.Tcpbw100;

import p2pradio.Messages;
import p2pradio.Radio;
import p2pradio.logging.FileLogHandler;
import p2pradio.logging.LogFormatter;
import p2pradio.logging.Logger;
import p2pradio.event.*;
import stream2stream.XML.DesEncrypter;
import stream2stream.XML.SettingsXML;

public class OptionsPanel extends JPanel implements BandwidthReceiver, Filter{
	private MainFrame mainframe;
	private boolean isServer;
	private OptionsPanel selfReference;
	private JCheckBox launchMediaPlayer, displayDebug, log, logAs,
	Sign_Or_Verify, enableMonitor, negativeLag, integratedMedia, internetRadio
	,internetRadioPreset, allowRemotePlayerConnections;
	private JButton logAsBrowse, testBandwidth;
	private JTextField verifiedUploadField, verifiedDownloadField, uploadField, 
	downloadField, portField, logAsField, monitorAddress, multicastAddress;
	private JTextArea presetInformation;
	//private JRadioButton internetRadio, lanRadio;
	private ButtonGroup bandwidthMode;
	private String[] sModes = {"TCP", "UDP", "MULTICAST+"};
	private String[] mModes = {"TCP", "UDP"};
	private JLabel verifiedMaxUpload, verifiedMaxDownload, ip;
	private SettingsXML xml;
	private boolean clear;
	private TreeMap selectionToUrl;
	private JList links;
	private DefaultListModel linksModel;
	private TreeMap deletedSelectionToUrl;
	private TreeMap deletedUrlToStationname;
	private TreeMap urlToStationname;
	private JTextArea messages;
	private JScrollPane messagesPane;
	private JSpinner MinimumChildrenClientsMustServe, multicastTTL;
	private JComboBox messageMode, streamMode, presets;
	public static final int maxMinChildrenClientsMustServe = 10;
	public OptionsPanel(MainFrame mainframe){
		
		//******************************************GENERAL*******************************************************
		deletedSelectionToUrl = new TreeMap();
		deletedUrlToStationname = new TreeMap();
		selfReference = this;
		xml = mainframe.getSettingsXML();
		isServer = mainframe.getIsServer();
		this.mainframe = mainframe;
		JButton save = new JButton(Messages.getString("OptionsPanel.SAVE"));
		JButton cancel = new JButton(Messages.getString("OptionsPanel.CANCEL"));
		
		BoxLayout optionsLayout = new BoxLayout(this, BoxLayout.PAGE_AXIS);
		setLayout(optionsLayout);
		JTabbedPane optionsPane = new JTabbedPane();
		
		JPanel general = new JPanel();
		SpringLayout generalLayout = new SpringLayout();
		general.setLayout(generalLayout);
		launchMediaPlayer = new JCheckBox(Messages.getString("OptionsPanel.GENERAL_LAUNCH_MEDIA_PLAYER"));
	    launchMediaPlayer.setMnemonic(KeyEvent.VK_L); 
	    launchMediaPlayer.setSelected(Radio.startMediaPlayer);
	    launchMediaPlayer.addActionListener(new ActionListener()
	    {
	    	public void actionPerformed(ActionEvent e)
	    	{
	  				integratedMedia.setEnabled(launchMediaPlayer.isSelected());
	   		}
   		}); 		
	    
	    integratedMedia = new JCheckBox(Messages.getString("OptionsPanel.USE_INTEGRATED_PLAYER"));
	    integratedMedia.setSelected(xml.getUseIntegratedPlayer());
	    integratedMedia.setEnabled(launchMediaPlayer.isSelected());
	    
	    
	    displayDebug = new JCheckBox(Messages.getString("OptionsPanel.GENERAL_DISPLAY_DEBUG"));
	    displayDebug.setMnemonic(KeyEvent.VK_D); 
	    displayDebug.setSelected(Radio.displayDebugMessages);
	    
	    log = new JCheckBox(Messages.getString("OptionsPanel.GENERAL_LOG"));
	    log.setSelected(mainframe.getLog());
	    
	    logAs = new JCheckBox(Messages.getString("OptionsPanel.GENERAL_LOG_AS"));
	    logAsBrowse = new JButton(Messages.getString("OptionsPanel.GENERAL_LOG_AS_BROWSE"));
	    logAsField = new JTextField();
		
		String logName = mainframe.getLogFilename();
		logAsField.setText(logName);
		boolean bLogAs = (logName != null) && (!logName.equals("")) ;
		logAsBrowse.setEnabled(bLogAs);
		logAs.setSelected(bLogAs);
		logAsField.setEnabled(bLogAs);
		logAsField.setMaximumSize(logAsField.getPreferredSize());
		logAsField.setMinimumSize(logAsField.getPreferredSize());
	    logAs.addActionListener(new ActionListener()
	    {
			public void actionPerformed(ActionEvent e)
			{
				logAsBrowse.setEnabled(logAs.isSelected());
				logAsField.setEnabled(logAs.isSelected());
			}
		}); 		
	    logAsBrowse.addActionListener(new ActionListener()
	    {
			public void actionPerformed(ActionEvent e)
			{
//				Create a file chooser
				final JFileChooser fc = new JFileChooser();
				//In response to a button click:
				int returnVal = fc.showSaveDialog(selfReference.mainframe);
				if (returnVal == JFileChooser.APPROVE_OPTION) 
				{
		            File file = fc.getSelectedFile();
		            String logName = file.getAbsolutePath();
		            logAsField.setText(logName);
		        } 
			}
		}); 	
	    
	    general.add(launchMediaPlayer);
	    addEmpty(general);
	    general.add(integratedMedia);
	    addEmpty(general);
	    general.add(displayDebug);
	    addEmpty(general);
	    general.add(log);
	    addEmpty(general);
	    general.add(logAs);
	    general.add(logAsBrowse);
	    general.add(logAsField);
	    addEmpty(general);
	   
	    int rows = 2;
	    SpringUtilities.makeCompactGrid(general,
                general.getComponentCount() / rows, rows, //rows, cols
                6, 6,        //initX, initY
                0, 0);       //xPad, yPad
		
	    
	    //**************************************ADVANCED*********************************************
		JPanel advanced = new JPanel();
		SpringLayout advancedLayout = new SpringLayout();
		advanced.setLayout(advancedLayout);
		
		
		enableMonitor = new JCheckBox(Messages.getString("OptionsPanel.ADVANCED_ENABLE_MONITOR"));
		enableMonitor.setSelected(xml.getEnableMonitor());
		
			
		negativeLag = new JCheckBox(Messages.getString("OptionsPanel.ADVANCED_SHOW_NLAG"));
		negativeLag.setSelected(mainframe.negativeLagEnabled());
		JLabel warning = new JLabel(Messages.getString("OptionsPanel.ADVANCED_WARNING"));
		Font f = new Font("warning", Font.PLAIN, 16);
		warning.setFont(f);
		warning.setMaximumSize(warning.getPreferredSize());
		Sign_Or_Verify = new JCheckBox(Messages.getString("OptionsPanel.ADVANCED_VERIFY"));
		Sign_Or_Verify.setMnemonic(KeyEvent.VK_V);
		Sign_Or_Verify.setSelected(Radio.signOrVerify);
		
		advanced.add(warning);
		addEmpty(advanced);
		if (!isServer)
		{
			advanced.add(Sign_Or_Verify);
			addEmpty(advanced);
			advanced.add(enableMonitor);
			addEmpty(advanced);
		}
		advanced.add(negativeLag);
		addEmpty(advanced);

		SpringUtilities.makeCompactGrid(advanced,
                advanced.getComponentCount() / rows, rows, //rows, cols
                6, 6,        //initX, initY
                0, 0);       //xPad, yPad
		
		//**************************************************HISTORY********************************************
		JPanel history = new JPanel();
		JButton clearHistory = new JButton(Messages.getString("OptionsPanel.HISTORY_CLEAR"));
		clearHistory.addActionListener(new ActionListener()
	    {
			public void actionPerformed(ActionEvent e)
			{
				deletedUrlToStationname = urlToStationname;
				linksModel.clear();
			}
		}); 		
		JButton delete = new JButton(Messages.getString("OptionsPanel.HISTORY_DELETE"));
		delete.addActionListener(new ActionListener()
	    {
			public void actionPerformed(ActionEvent e)
			{
				int size = linksModel.getSize();
				int selectedIndex = links.getSelectedIndex();
				Object selection = linksModel.get(selectedIndex);
				Object url = selectionToUrl.get(selection);
				Object stationname = urlToStationname.get(url);
				
				deletedSelectionToUrl.put(selection, url);
				deletedUrlToStationname.put(url, stationname);
				linksModel.remove(selectedIndex);
				size--;
				if (selectedIndex < size)
					links.setSelectedIndex(selectedIndex);
				else
					links.setSelectedIndex(size - 1);
			}
		}); 	
		
		//history.setLayout(new BoxLayout(history, BoxLayout.PAGE_AXIS));
		history.setLayout(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();
		selectionToUrl = mainframe.getSelectionToUrl();
		urlToStationname = mainframe.getUrlToStationname();
		Object[] linksArray = selectionToUrl.keySet().toArray();
		
		linksModel = new DefaultListModel();
		for (int i = 0; i < linksArray.length; i++)
		{
			linksModel.add(i, linksArray[i]);
		}
		
		links = new JList(linksModel);
		
		JScrollPane linksScroller = new JScrollPane(links);
		//linksScroller.setPreferredSize(new Dimension(20, 20));
		links.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
		
		c.anchor = GridBagConstraints.PAGE_START;
		
		c.weightx = .1;
		c.weighty = .1;
		c.fill = GridBagConstraints.BOTH;
		c.gridwidth = 3;
		c.gridx = 0;
		c.gridy = 0;
		history.add(clearHistory, c);
		c.weightx = 1;
		c.weighty = 1;
		c.fill = GridBagConstraints.BOTH;
		c.gridwidth = 2;
		c.gridheight = 3;
		c.gridy = 1;
		history.add(linksScroller, c);
		c.fill = GridBagConstraints.NONE;
		c.weightx = .1;
		c.gridwidth = 1;
		c.gridheight = 1;
		c.gridx = 2;
		c.gridy = 1;
		c.insets = new Insets(10, 0, 0, 0);

⌨️ 快捷键说明

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