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

📄 mediaserverpanel.java

📁 Its video trNSMITT FILE USING JMF
💻 JAVA
字号:
/*  MediaServerPanel.java
 *
 *  Panel displaying active CamProcessors and CamControllers.
 *
 *  Copyright (C) 2002 by Frank McCown
 *  University of Arkansas at Little Rock
 *  July 2002
 *
 */

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

import rowc.*;
import rowc.event.CamControllerListener;
import rowc.event.WebCamListener;
import rowc.event.MediaArchiveListener;
import rowc.event.MediaArchiveEvent;


public class MediaServerPanel extends JPanel implements MediaArchiveListener,
	WebCamListener, CamControllerListener
{
 	private VideoArchivePanel archivePanel;
 	private JList processorList;
 	private Vector processors;
 	private JList controllerList;
 	private Vector controllers;
 	private JLabel lblInfo;
 	
	public MediaServerPanel()
	{		
		// Register for various events
		Server.mediaStore.addMediaArchiveListener(this);
		Server.registrationObj.addWebCamListener(this);
		Server.registrationObj.addCamControllerListener(this);
		
		setLayout(new GridBagLayout());
	
		lblInfo = new JLabel("info");
		lblInfo.setForeground(Color.red);
		
		processors = new Vector();
		processorList = new JList(processors);
		
		controllers = new Vector();
		controllerList = new JList(controllers);
		
		JScrollPane processorScrollPane = new JScrollPane(processorList);
		JScrollPane controllerScrollPane = new JScrollPane(controllerList);
		
		archivePanel = new VideoArchivePanel();
		
		// GridBagConstraints(int gridx, int gridy, int gridwidth, int gridheight, double weightx, double weighty, 
		//   int anchor, int fill, Insets insets(T,L,B,R), int ipadx, int ipady) 
		
		// Add components to container
		
		// Top row:
		add(new HeaderPanel(), new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 10, 10));

		// Second row:
		add(new JLabel("Cam Processors:"), new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
            GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
		add(new JLabel("Cam Controllers:"), new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
            GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 15, 5, 5), 0, 0));

		// Third row:
		add(processorScrollPane, new GridBagConstraints(0, 2, 1, 1, 0.0, 1.0,
            GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 5, 5, 5), 0, 0));
    add(controllerScrollPane, new GridBagConstraints(1, 2, 1, 1, 0.0, 1.0,
            GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 15, 5, 5), 0, 0));
      
    // Forth row:
    add(archivePanel, new GridBagConstraints(0, 3, 2, 1, 1.0, 1.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 0, 0, 5), 0, 0));

    // Fifth row:
    add(lblInfo, new GridBagConstraints(0, 4, 2, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 10, 10));

	}
 	
	// Called when MediaStoreImpl receives a new video
	public void addVideo(MediaArchiveEvent event)
	{
		String loc = event.getLocation();
		archivePanel.addNewVideoFromLocation(loc);
	}
	
	// Called when MediaStoreImpl deletes a video
	public void removeVideo(MediaArchiveEvent event)
	{
		String loc = event.getLocation();
		archivePanel.removeVideoFromLocation(loc);
	}
	
	// Called when RegistrationImpl is notified of a new web cam
	public void addWebCam(rowc.event.WebCamEvent event)
	{
		String loc = event.getLocation();
		processors.add(loc);
		
		// Make list update itself with new web cam
		processorList.setListData(processors);
	}
	
	// Called when web cam is no longer available
	public void removeWebCam(rowc.event.WebCamEvent event)
	{
		String loc = event.getLocation();
		processors.remove(loc);
		
		// Make list update itself with new web cam
		processorList.setListData(processors);
	}
	
	public void addCamController(rowc.event.CamControllerEvent event)
	{
		String name = event.getName();
		controllers.add(name);
		controllerList.setListData(controllers);
	}
	
	public void removeCamController(rowc.event.CamControllerEvent event)
	{
		String name = event.getName();
		controllers.remove(name);
		controllerList.setListData(controllers);
	}
	
	private void showError(String error)
	{
		lblInfo.setText("");
		JOptionPane.showMessageDialog(this, error, "Media Server Error",
						JOptionPane.ERROR_MESSAGE);
	}
		
	public void setInfo(String info)
	{
		lblInfo.setText(info);	
	}
	
	/********************************************************************

		Inner class for top panel of Media Server.
		
	********************************************************************/
	
	class HeaderPanel extends JPanel
	{
		public HeaderPanel()
		{
			setLayout(new BorderLayout());
		
			ImageIcon icon = new ImageIcon("rowc.gif");
			JLabel imageLabel = new JLabel(icon);
			imageLabel.setText("      ");
			add(imageLabel, BorderLayout.WEST);
			
			Box box = Box.createVerticalBox();
			box.add(new JLabel("Remote Object Webcam Controller (ROWC)"));
			box.add(new JLabel("by Frank McCown"));
			box.add(new JLabel("University of Arkansas at Little Rock"));
			
			add(box, BorderLayout.CENTER);
		}
	}

	/********************************************************************

		Inner class for displaying all archived media.
		
	********************************************************************/
	
	class VideoArchivePanel extends JPanel
	{
		private JComboBox archiveLocationsComboBox;
		private VideoTable videoTable = new VideoTable();
		private String archiveCurrentLocation = "";
		
		public VideoArchivePanel()
		{
			setLayout(new GridBagLayout());
					
			archiveLocationsComboBox = new JComboBox();
			archiveLocationsComboBox.addItemListener(new ItemListener()
				{
					public void itemStateChanged(ItemEvent e)
					{
						Object obj = archiveLocationsComboBox.getSelectedItem();
						if (obj != null)
						{
							archiveCurrentLocation = obj.toString();
													
							// Show videos for this location
							videoTable.populateVideoTable(archiveCurrentLocation,
								Server.mediaStore);
						}
						else
						  archiveCurrentLocation = "";
						
						System.out.println("Selected archive location " + archiveCurrentLocation);
					}
				}
			);
			
			populateArchiveLocationsComboBox();
			
			JScrollPane scrollPane = new JScrollPane(videoTable);
			
			// GridBagConstraints(int gridx, int gridy, int gridwidth, int gridheight, double weightx, double weighty, 
			//   int anchor, int fill, Insets insets, int ipadx, int ipady) 

			add(new JLabel("Video Archive:"), new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
	            GridBagConstraints.NORTHWEST, GridBagConstraints.NORTH, new Insets(0, 10, 10, 0), 0, 0));
		
			add(archiveLocationsComboBox, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
	            GridBagConstraints.WEST, GridBagConstraints.NORTH, new Insets(0, 10, 10, 0), 0, 0));

			add(scrollPane, new GridBagConstraints(0, 1, 2, 1, 2.0, 2.0,
	            GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 10, 10, 0), 0, 0));
	
		}
		
		public void addNewVideoFromLocation(String location)
		{
			// Add this location to combo box if it's not already there
			int items = archiveLocationsComboBox.getItemCount();
			boolean found = false;
			for (int i = 0; i < items && !found; i++)
			{
				String loc = (String) archiveLocationsComboBox.getItemAt(i);
				if (loc.equals(location))
					found = true;
			}
			
			if (!found)
			{
				System.out.println("Adding new location: " + location);
				archiveLocationsComboBox.addItem(location);
			}
			else if (archiveCurrentLocation.equals(location))
			{
				// Add new video to the list.  
				videoTable.populateVideoTable(location, Server.mediaStore);  
			}
		}
		
		public void removeVideoFromLocation(String location)
		{
			// Remove video from the list if we're viewing it's location
			if (archiveCurrentLocation.equals(location))
			{
				videoTable.populateVideoTable(location, Server.mediaStore);
			}
		}
		
		private void populateArchiveLocationsComboBox()
		{
			// Location combo box- Retrieve locations from DB

			String[] loc = null;
			
			try	
			{
				System.out.println("Retrieving archive locations from MediaStore...");
				loc = Server.mediaStore.getArchiveLocations();
							
				if (loc.length != 0)
				{
					if (!loc[0].equals(""))
					{
						for (int i=0; i < loc.length; i++)
							archiveLocationsComboBox.addItem(loc[i]);

						archiveCurrentLocation = (String) archiveLocationsComboBox.getItemAt(0);
						
						// Show videos for this location
						videoTable.populateVideoTable(archiveCurrentLocation,
								Server.mediaStore);
					}
				}
				else
				{
					setInfo("No archived video available yet.");
				}
			}
			catch (rowc.MediaStorePackage.LocationsUnavailable e)	
			{
				System.out.println("Unable to get locations from database.");
				showError("Error retrieving locations from the Server.");
			}
			catch (Exception e)	
			{
				System.out.println("Unable to get locations from Server.");
				e.printStackTrace();
				showError("Error retrieving locations from the Server.");
			}
		}
	} // end VideoArchivePanel class
	
}	// end MediaServerPanel class

⌨️ 快捷键说明

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