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

📄 optionspanel.java

📁 java语言开发的P2P流媒体系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	                serverOptions.getComponentCount() / rows, rows, //rows, cols
	                6, 6,        //initX, initY
	                0, 0);       //xPad, yPad
			SpringUtilities.makeCompactGrid(serverPresetsOptions,
	                serverPresetsOptions.getComponentCount() / rows, rows, //rows, cols
	                6, 6,        //initX, initY
	                0, 0);       //xPad, yPad
			server.add(serverMessage, BorderLayout.PAGE_START);
			server.add(serverOptions, BorderLayout.CENTER);
			
			serverPresets.add(serverPresetsOptions, BorderLayout.PAGE_START);
			serverPresets.add(infoScroll, BorderLayout.PAGE_END);
			
			mainServer.addTab(Messages.getString("OptionsPanel.SERVER_PRESETS_TAB"), serverPresets);
			mainServer.addTab(Messages.getString("OptionsPanel.SERVER_EDIT_TAB"), server);
			
			optionsPane.addTab(Messages.getString("OptionsPanel.SERVER_TAB"), mainServer);
        }
        
        
		
        
		
		
		
		//save.setMaximumSize(save.getPreferredSize());
		//cancel.setMaximumSize(save.getPreferredSize());
		
		JPanel saveOrcancel = new JPanel();
		BoxLayout scLayout = new BoxLayout(saveOrcancel, BoxLayout.LINE_AXIS);
		saveOrcancel.setLayout(scLayout);
		saveOrcancel.add(save);
		saveOrcancel.add(cancel);
		add(optionsPane);
		add(saveOrcancel);
		
		save.addActionListener(new ActionListener()
	    {
			public void actionPerformed(ActionEvent e)
			{
				String TRUE = SettingsXML.TRUE;
				String FALSE = SettingsXML.FALSE;
				
				/* Bandwidth 
				 *********************************************************************************************
				 * 
				 * Unverified - LAN USE
				 * -------------------------------------------------------------------------------------------
				 * NOTE:  These numbers can be anything specified.  
				 * It is recommended to use unverified on networks other than the internet (LANs).
				 * Do not use unverified over the internet.  People can lie or be clueless about their bandwidth.
				 * 
				 * Upload - Can be any floating point negative or positive. >=0 represents bandwidth in KB/s.  
				 * < 0 represents children that can be served(e.g. -3 will serve up to 3 children).  Negatives 
				 * will be rounded down to integers.
				 *
				 * Download - Similar to upload
				 * -------------------------------------------------------------------------------------------
				 * 
				 * 
				 * Verified - INTERNET USE
				 * -------------------------------------------------------------------------------------------
				 * Testing bandwidth stops users from lieing about there bandwidth and helps users
				 * who don't know about bandwidth.  
				 * 
				 * 
				 * Verified Maximum Upload - The maximum amount you can upload, tested by the speed tester.
				 * This number cannot be specified
				 * 
				 * Verified Maximum Download - Similar to Verified Maximum Upload
				 * 
				 * Verified Upload Limit - The amount of upload bandwidth you are dedicating.  
				 * This can be specified, but it is recommended not to.
				 * Must be between Verified Max and 0,
				 * Verified Max >= Verified Upload Limit >= 0
				 * 
				 * Verified Download Limit - Similar to Verified Upload limit
				 * ---------------------------------------------------------------------------------------------
				 *
				 ***********************************************************************************************
				 */
				
				//--LAN
				boolean invalidUpload = false;
				double upload = 0;
				try{
					upload = Double.parseDouble(uploadField.getText());
					//if (upload < 0)
						//invalidUpload = true;
				}
				catch (NumberFormatException error){
					invalidUpload = true;
				}
				
				if (invalidUpload)
				{
					JOptionPane.showMessageDialog(selfReference, Messages.getString("OptionsPanel.ERROR_INVALID_UPLOAD"),
							Messages.getString("OptionsPanel.ERROR_INVALID_UPLOAD_TITLE"), JOptionPane.ERROR_MESSAGE);
				}
				
				boolean invalidDownload = false;
				double download = 0;
				try{
					download = Double.parseDouble(downloadField.getText());
					//if (upload < 0)
						//invalidUpload = true;
				}
				catch (NumberFormatException error){
					invalidDownload = true;
				}
				
				if (invalidDownload)
				{
					JOptionPane.showMessageDialog(selfReference, Messages.getString("OptionsPanel.ERROR_INVALID_DOWNLOAD"),
							Messages.getString("OptionsPanel.ERROR_INVALID_DOWNLOAD_TITLE"), JOptionPane.ERROR_MESSAGE);
				}
				
				
			    
		        
				
				
				boolean invalidPort = false;
				int port = 0;
				try{
					port = Integer.parseInt(portField.getText());
					if (port <= 1024  || port > 65535)
						invalidPort = true;
				}
				catch (NumberFormatException error){
					invalidPort = true;
				}
				if (invalidPort)
				{
					JOptionPane.showMessageDialog(selfReference, Messages.getString("OptionsPanel.ERROR_INVALID_PORT"),
							Messages.getString("OptionsPanel.ERROR_INVALID_PORT_TITLE"), JOptionPane.ERROR_MESSAGE);
				}
				boolean invalidLogAs = false;
				
				String potentialFile = logAsField.getText();
				if (logAs.isSelected())
				{
					if (potentialFile != null || potentialFile.equals(""))
					{
						try {
							FileOutputStream testDump = new FileOutputStream(potentialFile);
							xml.setLogAs(potentialFile);
							
						} catch (FileNotFoundException e1) {
							invalidLogAs = true;
							JOptionPane.showMessageDialog(selfReference, Messages.getString("OptionsPanel.ERROR_INVALID_FILENAME", potentialFile),
									Messages.getString("OptionsPanel.ERROR_INVALID_FILENAME_TITLE"), JOptionPane.ERROR_MESSAGE);
						} 
					}
				}
				
				
				if (invalidPort || invalidUpload || invalidLogAs || invalidDownload)
					return;
				
				//--Internet
				try 
				{
					double maxUpload = Double.parseDouble(verifiedMaxUpload.getText());
					double maxDownload = Double.parseDouble(verifiedMaxDownload.getText());
					double actualUpload = Double.parseDouble(verifiedUploadField.getText());
					double actualDownload = Double.parseDouble(verifiedDownloadField.getText());
					if (actualDownload > maxDownload || actualDownload < 0)
					{
						JOptionPane.showMessageDialog(selfReference, Messages.getString("OptionsPanel.ERROR_INVALID_VERIFIED_DOWNLOAD", "" + maxDownload),
								Messages.getString("OptionsPanel.ERROR_INVALID_VERIFIED_DOWNLOAD_TITLE"), JOptionPane.ERROR_MESSAGE);
						return;
					}
					if (actualUpload > maxUpload || actualUpload < 0)
					{
						JOptionPane.showMessageDialog(selfReference, Messages.getString("OptionsPanel.ERROR_INVALID_VERIFIED_UPLOAD", "" + maxUpload),
								Messages.getString("OptionsPanel.ERROR_INVALID_VERIFIED_UPLOAD_TITLE"), JOptionPane.ERROR_MESSAGE);
						return;
					}
					xml.setInternetMax(verifiedMaxUpload.getText(), verifiedMaxDownload.getText(), ip.getText());
					xml.Set_Internet_Upload_Limit(verifiedUploadField.getText());
					xml.Set_Internet_Download_Limit(verifiedDownloadField.getText());
				}
				catch (NumberFormatException numberException)
				{
					
				}
				
				xml.setLANUpload(upload);
				xml.setLANDownload(download);
				xml.setPort(port);
				xml.setMediaPlayerStartup(launchMediaPlayer.isSelected());
				xml.setUseIntegratedPlayer(integratedMedia.isSelected());
				xml.setDisplayDebug(displayDebug.isSelected());
				xml.setLogByDate(log.isSelected());
				
				xml.setSignOrVerify(Sign_Or_Verify.isSelected());
				if (isServer)
				{
					xml.setUseVerifiedBandwidth(internetRadio.isSelected());
					String min = getTextField(MinimumChildrenClientsMustServe).getText();
					
					xml.setMinimumChildrenClientsMustServe(Integer.parseInt(min));
					xml.setMonitorAddress(monitorAddress.getText());
					xml.setMulticastAddress(multicastAddress.getText());
					String ttl = getTextField(multicastTTL).getText();
					xml.setTTL(Integer.parseInt(ttl));
					xml.setPreset(presets.getSelectedIndex());
					xml.setMessageMode(messageMode.getSelectedIndex());
					xml.setStreamMode(streamMode.getSelectedIndex());
					xml.Set_Allow_Connections_From_Remote_Hosts(allowRemotePlayerConnections.isSelected());
				}
				
				xml.setEnableMonitor(enableMonitor.isSelected());
				xml.setNegativeLagEnabled(negativeLag.isSelected());
				
				xml.deleteLinks(deletedUrlToStationname);
				xml.flush();
				
				selfReference.mainframe.closeOptions();
				selfReference.mainframe.readXML();
				JOptionPane.showMessageDialog(selfReference.mainframe, Messages.getString("MainFrame.SETTINGS_SAVED", Radio.s2sName),
						Messages.getString("MainFrame.SETTINGS_SAVED_TITLE"), JOptionPane.INFORMATION_MESSAGE);
				
			}
		}); 	
		cancel.addActionListener(new ActionListener()
	    {
			public void actionPerformed(ActionEvent e)
			{
				selfReference.mainframe.closeOptions();
			}
		}); 	
	}
	private void addEmpty(JPanel panel) 
	{									
		JLabel empty = new JLabel();	
		panel.add(empty);
	}
	
	public JPanel getJPanel(){
		return selfReference;
	}
	public void setBandwidth(double maxUpload, double maxDownload, String IP) {
		if (isServer && (xml.getMonitorAddress() == null || xml.getMonitorAddress().equals("")))
			monitorAddress.setText(IP);
		DecimalFormat sf3 = new DecimalFormat("0.000");
		if (maxUpload != -1)
		{
			double maxUploadBandwidth = maxUpload - 1.0;  //Designate 1KB/s for data messages
			verifiedMaxUpload.setText(sf3.format(maxUploadBandwidth));
			verifiedUploadField.setText(sf3.format(maxUploadBandwidth));
		}
		if (maxDownload != -1)
		{
			double maxDownloadBandwidth = maxDownload - 1.0;  //Designate 1KB/s for data messages
			verifiedMaxDownload.setText(sf3.format(maxDownloadBandwidth));
			verifiedDownloadField.setText(sf3.format(maxDownloadBandwidth));
		}
		System.out.println("ip:" + IP);
		ip.setText(IP);
		selfReference.remove(messagesPane);
		//mainframe.setOptionsSelected();
	}
	public boolean isLoggable(LogRecord record)
	{
		if (record.getLevel().intValue() < Level.INFO.intValue())
		{
			return Radio.displayDebugMessages;
		}
		else
		{
			return true;
		}
	}
	/**
     * Return the formatted text field used by the editor, or
     * null if the editor doesn't descend from JSpinner.DefaultEditor.
     */
	public JFormattedTextField getTextField(JSpinner spinner) {
        JComponent editor = spinner.getEditor();
        if (editor instanceof JSpinner.DefaultEditor) {
            return ((JSpinner.DefaultEditor)editor).getTextField();
        } else {
            System.err.println("Unexpected editor type: "
                               + spinner.getEditor().getClass()
                               + " isn't a descendant of DefaultEditor");
            return null;
        }
    }
}

⌨️ 快捷键说明

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