`

聚合IpCamera到自己页面

    博客分类:
  • Lab
阅读更多
public class RobotPage extends Page {
	  private final static String CSS_ROBOT_PAGE = "robot-page";
	  private final static String LOCALHOST = "127.0.0.1";
	  private final static String HTMLTEMPLATE_VIDEO = "<iframe width= 320 height= 240 scrolling=\"no\" src=\"http://%u:%p@%h/ImageViewer?Direction=&Resolution=320x240&Quality=Standard&Size=STD&PresetOperation=Move&Data=0&Frame2=PanTilt&Type=&Language=0&RPeriod=65535&Sound=Enable&Mode=JPEG&SendMethod=1&View=Normal>"
          + "</iframe>";  //the video source for html
	  private final static String HTMLTEMPLATE_CONTROL = "<iframe width= 0 height= 0 scrolling=\"no\" src=\"http://%u:%p@%h/nphControlCamera?Direction=%d&Resolution=320x240&Quality=Standard&Mode=JPEG&RPeriod=65535&Size=STD&PresetOperation=Move&Language=0>"
          + "</iframe>";  //the ip-camera-control:direction source for html
      private final static String XML_FILE_INSTRUCTION = "robot-instruction.xml";
      private final static String XML_FILE_KIOSKINFO   = "kiosk-information.xml";
	  
	  private final static String CSS_RENTAL_LEFT_BUTTON   = "robot-left-navibutton";
	  private final static String CSS_RENTAL_RIGHT_BUTTON  = "robot-right-navibutton";
	  private final static String CSS_INSTRUCTION_GRID     = "robot-instruction-grid";
	  private final static String CSS_LOG_SCROLL_PANEL     = "robot-log-scroll-panel";
	  private final static String CSS_ROBOT_NAVI_PANEL     = "robot-navi-buttons-panel";
	  private final static String CSS_GROUP_BUTTONS_GRIDS  = "robot-group-buttons-grid";
	  private final static String CSS_IPCAMERA_DIRECTION   = "ipcamera-direction-grid";
	  private final static String CSS_IPCAMERA_BRIGHTNESS  = "ipcamera-brightness-grid";
	  private final static String CSS_WINDOW_CLOSE         = "window-close-button";
	  
	  private final static String CSS_MSG   = "json-error-msg";
	  private final static String ROOT_NAME = "all";
	  
	  private static final int PAGESIZE        = 6;  //will hold the number of instruction(each inst is a button).
	  private static final int MAXCOL_SIZE     = InstPanel.MAX_INSTTUCTION_NUM;  //in one row, there's 3 instruction button.
	  private static final int MAXROW_SIZE     = PAGESIZE / MAXCOL_SIZE ;  // each page will hold those rows.
	  
	  private static int _currentPage = 0;   //the state of current page number.
	  private static int _totalPage   = 0;   //the total of page number.
	  
//	  protected HashMap	_dataNames	= new HashMap();
//	  protected ArrayList _valueListenersNames = new ArrayList();
//	  protected ArrayList _valueListeners      = new ArrayList();
//	  protected ArrayList _errorListenersNames = new ArrayList();
//	  protected ArrayList _errorListeners      = new ArrayList();
	  
	  private static ArrayList _instList      = new ArrayList(); //store Instruction
	  private static ArrayList _instPanelList = new ArrayList(); //store InstPanel;
	  private static ParseKioskInfo _parseKioskInfo = null;      //it's global      
	  protected String _group = ROOT_NAME;                                   //story current group name
	  
	  private CommandPushButton		_cmdPrevPage;         // navi button <<
	  private CommandPushButton		_cmdNextPage;         // navi button >>
	  private Grid _instGrid;                             // to arrage instruction panel...
	  private VerticalPanel _pageContentPanel;            // the container of this page
	  private Label _errorMsg;
	  private HTML _logHtml;
	  private CustomScrollPanel _logContainer;
	  
	  private KioskSelectionPopup _kioskPopup;
	  private DataLabel _entryField;
	  private HTML _ipCameraVideo;
	  private HTML _ipCameraControl;
	

	public static PageInfo init(final Screen parent, final ScreenData data) {
		return new PageInfo("robot-test", parent) {
			public Page createInstance() {
				return new RobotPage("robot-test", parent, data);
			}
		};
	}

	public RobotPage(String token, final Screen parent, ScreenData data) {
		super(token, parent, data);

//		KioskConstants constants = Main.getConstants();
		
		// A vertical layout. this widget ready to prepare for xmlPanel...
		_pageContentPanel = new VerticalPanel();
		
		_pageContentPanel.setHorizontalAlignment(HorizontalPanel.ALIGN_LEFT);
		initWidget(_pageContentPanel);
		setStyleName(CSS_ROBOT_PAGE);
	}

	public void preShowPageExecute() {
//		KioskConstants constants = Main.getConstants();
		
//        // Page title
//		_pageTitle = PageTitle.getInstance();
//		_pageTitle.setVisible(true);
//		_pageTitle.setTitle("robot-instruction-test");
		
//		final NavigationMenu naviMenu = NavigationMenu.getInstance();
//		naviMenu.resetButtons();
		
		// reset movie language selection
//		_data.setValue( Rental.DATA_RENTAL_MOVIELANGUAGESELECTION_MOVIELANGUAGEID, "", null );
	     
//		super.preShowPageExecute();
	  _isBlocking = false;
	  _visible = true;
	  _hasBeenShown = true;
	  GetXML robotXml = new GetXML(XML_FILE_INSTRUCTION,_data,this,_pageContentPanel);
	  robotXml.call();
	  
	  new CancelIdleTimer().scheduleRepeating( 1000);
	  
	  //if there's no any password setting, don't show me.
	  if (Security.getPassword().length() > 0){
		  Security security = new Security(_data,this);
		  security.showSessionDialog();
	  }
	  
	
	  
//	  enableChangeListeners();
	}
	
	public void postHidePageExecute() {
	   _isBlocking = false;
	   _visible = false;
//	   disableChangeListeners();	
	}
	
	
	
	protected class GetXML {
		private ScreenData _screenData;
		private Page       _currPage;
		private String     _xmlFile;
		private VerticalPanel _pageContentPanel;
		
		protected GetXML(String xmlFile,ScreenData data,Page currentPage,VerticalPanel pageContentPanel){
			_xmlFile = xmlFile;
			_screenData = data;
			_currPage = currentPage;
			_pageContentPanel = pageContentPanel;
		}
		
		protected void call(){
			HTTPRequest.asyncGet(_xmlFile, new ResponseTextHandler() {
			      public void onCompletion(String responseText) {
			        // In the real world, this text would come as a RPC response. This
			        // technique is great for testing and samples though!
			    	  renderXML(responseText);
			      }
			      
			      public void dealWithRobotInstList(String xmlText,final VerticalPanel pageContentPanel) {
			   		  
			    	  // --------------------------------begin xmlParse-------------------------------- //
			    	  
			   		  Document robotInstDom = XMLParser.parse(xmlText);
			   	      Element topMostElement = robotInstDom.getDocumentElement();
			   	      // Must do this if you ever use a raw node list that you expect to be
			   	      // all elements.
			   	      XMLParser.removeWhitespace(topMostElement);

			   	  

			   	      _instList.clear();
			   	      NodeList insts = topMostElement.getElementsByTagName("inst");
			   	      for (int i = 0; i < insts.getLength(); i++) {
			   	    	  
			   	        Element inst = (Element) insts.item(i);
			   	        
			   	        Instruction robotInst = new Instruction();

			   	        String desc = inst.getAttribute("desc") == null ? "" : inst.getAttribute("desc");
			   	        robotInst.setDesc(desc);
			   	        String urlMap = inst.getAttribute("urlMap") == null ? "" : inst.getAttribute("urlMap");
			   	        robotInst.setUrlMap(urlMap);
			   	        String group = inst.getAttribute("group") == null ? "others" : inst.getAttribute("group");
			   	        robotInst.setGroup(group);
			   	        

			   	        NodeList params = inst.getChildNodes();
			   	        if(params == null){
			   	        	_instList.add(robotInst);
			   	        	continue;
			   	        }
			   	        Param[] robotInstParams = new Param[params.getLength()];
			   	        for(int j = 0; j < params.getLength(); j++) {

			   	              Element param = (Element) params.item(j);
			   	              robotInstParams[j] = new Param();
			   	              String name = param.getAttribute("name") == null ? "" : param.getAttribute("name");
			   	              robotInstParams[j].setName(name);
			   	              String paramDesc = param.getAttribute("desc") == null ? "" : param.getAttribute("desc");
			   	              robotInstParams[j].setDesc(paramDesc);
			   	              
			   	              String reg = param.getAttribute("regularExpression") == null ? "" : param.getAttribute("regularExpression");
			   	              robotInstParams[j].setRegularExpression(reg.trim());
			   	              String defaultValue = param.getAttribute("defaultValue") == null ? "" : param.getAttribute("defaultValue"); 
			   	              robotInstParams[j].setValue(defaultValue.trim());
			   	              
			   	              String min = param.getAttribute("min") == null ? "" : param.getAttribute("min");
			   	              robotInstParams[j].setMin(min.trim());
			   	              String max = param.getAttribute("max") == null ? "" : param.getAttribute("max"); 
			   	              robotInstParams[j].setMax(max.trim());
			   	              
//			   	              _data.addDataItem(robotInst.getUrlMap().trim()+name.trim(), ScreenData.STRING_TYPE, 55);
////			   	              if(!defaultValue.trim().equals("")){
//			   	            	 _data.setValue(robotInst.getUrlMap().trim()+name.trim(), defaultValue, null);
////			   	              }
			   	             
			   	              
			   	              
			   	        }
			   	       robotInst.setParams(robotInstParams);
				   	   _instList.add(robotInst);
			   	      }
			   	      
			   	   // --------------------------------end xmlParse--------------------------------
			   		  
			   	   // --------------------------------begin construct widget-------------------------------- //
			   	      
			   	 
		   	      _totalPage  = _instList.size() / PAGESIZE;
		   	      if( _totalPage * PAGESIZE < _instList.size() ){
		   	    	  _totalPage += 1;
		   	      }  
		   	      
		   	    
		   	      
		   	      final HorizontalPanel cmdPanel = new HorizontalPanel();
		   	      cmdPanel.setStyleName(CSS_ROBOT_NAVI_PANEL);
		   	      cmdPanel.setHorizontalAlignment(HorizontalPanel.ALIGN_LEFT);
		   	      {
			   		_cmdPrevPage = new CommandPushButton(/*"<<" */""); 
					_cmdPrevPage.setStyleName(CSS_RENTAL_LEFT_BUTTON);
					_cmdPrevPage.setVisible(false);					// default to set it invisible until I know the count
					
					_cmdNextPage = new CommandPushButton(/*">>" */"");
					_cmdNextPage.setStyleName(CSS_RENTAL_RIGHT_BUTTON);
					_currentPage = _instList.size() > 0 ? 1 : 0;
					_cmdNextPage.setVisible( _currentPage < _totalPage );		
					
					cmdPanel.add( _cmdPrevPage );
					cmdPanel.setCellVerticalAlignment( _cmdPrevPage, HorizontalPanel.ALIGN_TOP);
					
					cmdPanel.add( _cmdNextPage );
					cmdPanel.setCellVerticalAlignment( _cmdNextPage, HorizontalPanel.ALIGN_TOP);
			   	  }
		   	          
//		   	       cmdPanel.add(setTreeView());
		   	       setGroupButtons(cmdPanel,_currPage);
		   	       
		   	       
//		   	    	 Edit popup
//						_entryField = new DataLabel( _currPage, _data, RobotScreen.DATA_RENTAL_CONFIRMRENTAL_KIOSKID,
//								DataLabel.LABEL_ELLIPSES | DataLabel.LABEL_POPUP );
//						AllKiosks.getInstanceAndAddCompletionCommand(new Command(){
//							public void execute(){
////								 Kiosk popup
//								_kioskPopup = new KioskSelectionPopupExt( _currPage, 
//																		_data,
//																		RobotScreen.DATA_RENTAL_CONFIRMRENTAL_KIOSKID,
//																		CssDefn.CSS_DATAENTRYPOPUP_CELLNUMBER,
//																		new HTML("<H2>select the kiosk you want to test."),_entryField);
//								 //HB,2008/04/01, Step 4: add change listern,the third param is a widget have implements ChangeListener.
//								_data.addValueChangeListener( RobotScreen.DATA_RENTAL_CONFIRMRENTAL_KIOSKID, _entryField );
//
//								_entryField.setMap(AllKiosks.getInstance().getKioskMap());
//
//								// Edit button
//								CommandPushButton kioskButton = new CommandPushButton( "select <br>kiosk" );
//								kioskButton.setCommand( new SelectKioskCommand( _kioskPopup ));
//								
//							   cmdPanel.add(kioskButton);
//							}
//						});

						
		   	       
		   	       
		   	      
		   	       
		   	      
		   	      
		   	      
		   	       pageContentPanel.add(cmdPanel);
			   	      
			   	   HorizontalPanel instPanel = new HorizontalPanel();
			   	   instPanel.setHorizontalAlignment(HorizontalPanel.ALIGN_LEFT);
			   	   
			   	    //log: record the json value 
//			       RichTextArea log = new RichTextArea();
//			       log.setStyleName(NOTES_STYLE);
			   	   
			   	
			   	{
					_errorMsg = new Label();
					_errorMsg.setWordWrap(true);
					_errorMsg.setStyleName(CSS_MSG);
				}   
			   	   
			   	   
			   	_logHtml = new HTML();
	 	        _logContainer = new CustomScrollPanel( _logHtml );
	 	        _logContainer.setStyleName( CSS_LOG_SCROLL_PANEL );
	 	        
	 	        
//	 	        instPanel.add(setTreeView());
				   	
					{
						{
							_instGrid = new Grid(MAXROW_SIZE,MAXCOL_SIZE);
							_instGrid.setStyleName(CSS_INSTRUCTION_GRID);
							
							instPanel.add( _instGrid );
							instPanel.setCellVerticalAlignment( _instGrid, HorizontalPanel.ALIGN_TOP);
							{
								_instPanelList.clear();
								int currentRow = 0;
						   	    int currentCol = 0;
								for(Iterator iter = _instList.iterator(); iter.hasNext(); ){
						   	    	Instruction currentInst = (Instruction)iter.next();
						   	    	
						   	    	InstPanel tmpPanel = new InstPanel(currentInst,_logContainer,_logHtml,_errorMsg,_screenData,_currPage);
						   	    	_instPanelList.add(tmpPanel);
						   	    	
						   	    	if( currentRow <= MAXROW_SIZE - 1 ){
						   	    		_instGrid.setWidget(currentRow, currentCol,tmpPanel);
						   	    		_instGrid.getCellFormatter().setHorizontalAlignment( currentRow,
						   	    				currentCol,
						   	    				VerticalPanel.ALIGN_LEFT);
						   	    		_instGrid.getCellFormatter().setVerticalAlignment( currentRow,
						   	    				currentCol,
						   	    				VerticalPanel.ALIGN_TOP);
						   	    	}
						   	    	else {
						   	    		continue;
						   	    	}
						   	    	
						   	    	
						   	    	if( currentCol < MAXCOL_SIZE - 1 ){
						   	    		currentCol++;
						   	    	}
						   	    	else {
						   	    		currentRow++;
						   	    		currentCol = 0;
						   	    	}
						   	    	
						   	    	
						   	    	
						   	      }
							}
						}
						
						
						
						
						
						VerticalPanel ipCameraVerticalPanel = new VerticalPanel(); //for adding ipcamera
						{
							_ipCameraVideo = new HTML("");
							_ipCameraControl = new HTML("");
							ipCameraVerticalPanel.add(_ipCameraVideo);
							ipCameraVerticalPanel.add(_ipCameraControl);
							
							Grid directionGrid = new Grid(3,3); //for controling the direction
							directionGrid.setStyleName(CSS_IPCAMERA_DIRECTION);
							{
								Button up = new Button("↑", new ClickListener(){
							    	  public void onClick(Widget sender){
							    		  String ipcameraHost = "127.0.0.1";
							    		  if (_parseKioskInfo != null){
							    			  if (_parseKioskInfo.getCameraIpList().get(RobotScreen.DATA_RENTAL_CONFIRMRENTAL_KIOSKID) != null){
							    				  ipcameraHost = _parseKioskInfo.getCameraIpList().get(RobotScreen.DATA_RENTAL_CONFIRMRENTAL_KIOSKID).toString();
							    			  }
							    		  }
							    		 
							    		  directionPost(ipcameraHost,"TiltUp");
							    	  }
							    }); //for up direction
								directionGrid.setWidget(0, 1, up);
								
								Button left = new Button("←", new ClickListener(){
							    	  public void onClick(Widget sender){
							    		  String ipcameraHost = "127.0.0.1";
							    		  if (_parseKioskInfo != null){
							    			  if (_parseKioskInfo.getCameraIpList().get(RobotScreen.DATA_RENTAL_CONFIRMRENTAL_KIOSKID) != null){
							    				  ipcameraHost = _parseKioskInfo.getCameraIpList().get(RobotScreen.DATA_RENTAL_CONFIRMRENTAL_KIOSKID).toString();
							    			  }
							    		  }
							    		  directionPost(ipcameraHost,"PanLeft");
							    	  }
							    }); //for left direction
								directionGrid.setWidget(1, 0, left);
								
								Button original = new Button("o", new ClickListener(){
							    	  public void onClick(Widget sender){
							    		  String ipcameraHost = "127.0.0.1";
							    		  if (_parseKioskInfo != null){
							    			  if (_parseKioskInfo.getCameraIpList().get(RobotScreen.DATA_RENTAL_CONFIRMRENTAL_KIOSKID) != null){
							    				  ipcameraHost = _parseKioskInfo.getCameraIpList().get(RobotScreen.DATA_RENTAL_CONFIRMRENTAL_KIOSKID).toString();
							    			  }
							    		  }
							    		  homePositionPost(ipcameraHost);
							    	  }
							    }); //return to original
								directionGrid.setWidget(1, 1, original);
								
								Button right = new Button("→", new ClickListener(){
							    	  public void onClick(Widget sender){
							    		  String ipcameraHost = "127.0.0.1";
							    		  if (_parseKioskInfo != null){
							    			  if (_parseKioskInfo.getCameraIpList().get(RobotScreen.DATA_RENTAL_CONFIRMRENTAL_KIOSKID) != null){
							    				  ipcameraHost = _parseKioskInfo.getCameraIpList().get(RobotScreen.DATA_RENTAL_CONFIRMRENTAL_KIOSKID).toString();
							    			  }
							    		  } 
							    		  directionPost(ipcameraHost,"PanRight");
							    	  }
							    });   //for right direction
								directionGrid.setWidget(1, 2, right);
								
								Button down = new Button("↓", new ClickListener(){
							    	  public void onClick(Widget sender){
							    		  String ipcameraHost = "127.0.0.1";
							    		  if (_parseKioskInfo != null){
							    			  if (_parseKioskInfo.getCameraIpList().get(RobotScreen.DATA_RENTAL_CONFIRMRENTAL_KIOSKID) != null){
							    				  ipcameraHost = _parseKioskInfo.getCameraIpList().get(RobotScreen.DATA_RENTAL_CONFIRMRENTAL_KIOSKID).toString();
							    			  }
							    		  }
							    		  directionPost(ipcameraHost,"TiltDown");
							    	  }
							    });   //for down direction
								directionGrid.setWidget(2, 1, down);
							}
							ipCameraVerticalPanel.add(directionGrid);
							
							//for Brightness
							{
								ipCameraVerticalPanel.add(new HTML("<font color=green >Brightness</font>"));
								Grid brightnessGrid = new Grid(1,3);
								brightnessGrid.setStyleName(CSS_IPCAMERA_BRIGHTNESS);
								Button darker = new Button("-", new ClickListener(){
							    	  public void onClick(Widget sender){
							    		  directionPost(_data.getValue(RobotScreen.DATA_ROBOTSCREEN_KIOSK_IP),"Darker");
							    	  }
							    }); //become darker
								brightnessGrid.setWidget(0, 0, darker);
								
								Button defaultBrightness = new Button("o", new ClickListener(){
							    	  public void onClick(Widget sender){
							    		  directionPost(_data.getValue(RobotScreen.DATA_ROBOTSCREEN_KIOSK_IP),"DefaultBrightness");
							    	  }
							    }); //keep intact
								brightnessGrid.setWidget(0, 1, defaultBrightness);
								
								Button brighter = new Button("+", new ClickListener(){
							    	  public void onClick(Widget sender){
							    		  directionPost(_data.getValue(RobotScreen.DATA_ROBOTSCREEN_KIOSK_IP),"Brighter");
							    	  }
							    }); //become brighter
								brightnessGrid.setWidget(0, 2, brighter);	
							    ipCameraVerticalPanel.add(brightnessGrid);
							}
							
							
							Button closeWindow = new Button("Leave Robot-test", new ClickListener(){
						    	  public void onClick(Widget sender){
						    		  closeWindow();
						    	  }
						    }); //hit to close the gwt-window
							
							closeWindow.setStyleName(CSS_WINDOW_CLOSE);
							ipCameraVerticalPanel.add(new HTML(" "));
							ipCameraVerticalPanel.add(closeWindow);
							
							
						}
						
						instPanel.add(ipCameraVerticalPanel);
						
						pageContentPanel.add(instPanel);
						pageContentPanel.setCellHorizontalAlignment(instPanel, VerticalPanel.ALIGN_LEFT);
						pageContentPanel.setCellVerticalAlignment(instPanel, VerticalPanel.ALIGN_TOP);
						
						pageContentPanel.add(_errorMsg);
						pageContentPanel.add(_logContainer);
						pageContentPanel.setCellVerticalAlignment(_logContainer, VerticalPanel.ALIGN_TOP);
						CellPanelHelper.setParentCellStyleName( _logContainer, CssDefn.CSS_SIGNUP_AGREEMENT_TERMS_CONTENT_CELL );
					}
			   	      
					

			   	      
			   	      
			   	   // --------------------------------end   construct widget-------------------------------- //
					
					
					// -------------set navi menu command-------------
					_cmdPrevPage.setCommand(new PrevPageCommand());
					_cmdNextPage.setCommand(new NextPageCommand());
				  // -------------set navi menu command-------------
			   	            
			   	      
			   	  }
			      
			      
			      
			      //add two FlowPanel to this page.
			      private void renderXML(String xmlText) {
			     
//			        final TabPanel tab = new TabPanel();
//			        final FlowPanel xmlSource = new FlowPanel();
////			        final FlowPanel xmlParsed = new FlowPanel();
//			        final FlowPanel xmlrobot  = new FlowPanel();
////			        tab.add(xmlParsed, "Customer Pane");
//			        tab.add(xmlSource, "XML Source");
//			        tab.add(xmlrobot,"Robot Test");
//			        
//			        tab.selectTab(1);
//			        _pageContentPanel.add(tab);
//			        xmlPane(xmlText, xmlSource);
			        dealWithRobotInstList(xmlText, _pageContentPanel);
			      }
			
			      /**
			       * Show the raw XML.
			       * 
			       * @param xmlText
			       * @param xmlSource
			       */
//			      private void xmlPane(String xmlText, final FlowPanel xmlSource) {
//			        xmlText = xmlText.replaceAll("<", "&#60;");
//			        xmlText = xmlText.replaceAll(">", "&#62;");
//			        Label xml = new HTML("<pre>" + xmlText + "</pre>", false);
//			        xml.setStyleName(XML_LABEL_STYLE);
//			        xmlSource.add(xml);
//			      }
			      
			      
			  });
		}
		
		
		
	}
	
	
	
	//hit  next button to do this command
	protected class NextPageCommand implements Command {
		  public void execute(){
			  _currentPage++;
			  _instGrid.clear();
			  _cmdNextPage.setVisible( _currentPage < _totalPage);	
			  _cmdPrevPage.setVisible(true);
			  
			  
			  int currentRow = 0;
		   	  int currentCol = 0;
		   	  ArrayList relatedPanelList = filteredInstPanel(_group);
			  for(int i = (_currentPage -1)  * PAGESIZE; i >= 0 && i < _currentPage * PAGESIZE && i < relatedPanelList.size(); i++){
				  _instGrid.setWidget(currentRow, currentCol,(InstPanel)relatedPanelList.get(i));
		   	    	if(currentCol < MAXCOL_SIZE - 1){
		   	    		currentCol++;
		   	    	}
		   	    	else {
		   	    		currentRow++;
		   	    		currentCol = 0;
		   	    	}
			  }
		  }
	  }
	  
	  
      //hit prev button to do this command
	  protected class PrevPageCommand implements Command {
		 public void execute(){
			  _currentPage--;
			  _instGrid.clear();
			  _cmdNextPage.setVisible(_currentPage < _totalPage);	
			  _cmdPrevPage.setVisible(_currentPage > 1);
			  
			  
			  int currentRow = 0;
		   	  int currentCol = 0;
		   	  ArrayList relatedPanelList = filteredInstPanel(_group);
			  for(int i = (_currentPage -1 ) * PAGESIZE; i >= 0 && i < _currentPage * PAGESIZE && i < relatedPanelList.size(); i++){
				  _instGrid.setWidget(currentRow, currentCol,(InstPanel)relatedPanelList.get(i));
		   	    	if(currentCol < MAXCOL_SIZE -1 ){
		   	    		currentCol++;
		   	    	}
		   	    	else {
		   	    		currentRow++;
		   	    		currentCol = 0;
		   	    	}
			  }
		  }
	  }
	  
	  /**
	   * 
	   * add treeView,it has been expanded.
	   */
//	  private Tree setTreeView() {
//		    TreeItem root = new TreeItem(new Button(ROOT_NAME, new ClickListener(){
//		    	  public void onClick(Widget sender){
//		    		  setGroup(ROOT_NAME);
//		    		  _currentPage = 2;
//					  new PrevPageCommand().execute();
//		    	  }
//		    }));
//		    Set hashSet = new HashSet();
//		    
//		    //-----get all distinct group-----
//		    for(Iterator insts = _instList.iterator(); insts.hasNext(); ) {
//		    	Instruction inst = (Instruction) insts.next();
//		    	String group = inst.getGroup();
//		    	hashSet.add(group);
//		    	
//		    }
//		    //-----get all distinct group-----
//		    
//		    for(Iterator groups = hashSet.iterator(); groups.hasNext(); ) {
//		    	String group = groups.next().toString();
//		    	root.addItem(new Button(group, new ClickListener(){
//			    	  public void onClick(Widget sender){
//			    		    setGroup(((Button)sender).getText());
//			    		    _currentPage = 2;
//							new PrevPageCommand().execute();
//			    	  }
//			    }));
//		    }
//		    
//		    Tree t = new Tree();
//		    t.addItem(root);
//		    
//		    //----it's the only way to expand all nodes
//		    t.setSelectedItem(root.getChild(0));
//		    t.ensureSelectedItemVisible();
//            //----it's the only way to expand all nodes
//		    
//		    
//		    return t;
//	  }
	  
	  
	  
  private void setGroupButtons( HorizontalPanel container,final Page curentPage) {
	  final int MAX_COL = 6;
	  final Grid grid = new Grid();
	  grid.setCellPadding(30);
	  grid.setCellSpacing(30);
	  grid.setStyleName(CSS_GROUP_BUTTONS_GRIDS);
	  Button all = new Button(ROOT_NAME, new ClickListener(){
	  public void onClick(Widget sender){
		  setGroup(ROOT_NAME);
		  _currentPage = 2;
		  new PrevPageCommand().execute();
	   }
     });
	ArrayList instGroups = new ArrayList();
    
    //-----get all distinct group-----
    for(Iterator insts = _instList.iterator(); insts.hasNext(); ) {
    	Instruction inst = (Instruction) insts.next();
    	String group = inst.getGroup();
    	if(!instGroups.contains(group)){
    		instGroups.add(group);
    	}
    	
    	
    }
    //-----get all distinct group-----
    
    int rows = (instGroups.size() + 2) / MAX_COL;
    rows = (instGroups.size() + 2) % MAX_COL == 0 ? rows : rows + 2; 
    grid.resize(rows, MAX_COL);
    
    int row = 0;
    int col = 0;
    grid.setWidget(row, col, all);
    
    for(Iterator groups = instGroups.iterator(); groups.hasNext(); ) {
    	String group = groups.next().toString();
    	Button groupItem = new Button(group, new ClickListener(){
	    	  public void onClick(Widget sender){
	    		    setGroup(((Button)sender).getText());
	    		    _currentPage = 2;
					new PrevPageCommand().execute();
	    	  }
	    });
    	col++;
    	if (col==MAX_COL) {
    		col = 0;
    		row++;
    	}
    	grid.setWidget(row, col, groupItem);
    }  
    
//  	 Edit popup
	_entryField = new DataLabel( curentPage, _data, RobotScreen.DATA_RENTAL_CONFIRMRENTAL_KIOSKID,
			DataLabel.LABEL_ELLIPSES | DataLabel.LABEL_POPUP );
	//ParseKioskInfo.getInstance(xmlFile, nextCommand);
//	AllKiosks.getInstanceAndAddCompletionCommand(new Command(){
	AllKiosks.getInstanceAndAddCompletionCommand(new Command(){
		public void execute(){
			_parseKioskInfo = ParseKioskInfo.getInstance(XML_FILE_KIOSKINFO, new Command(){
				public void execute(){
//					 Kiosk popup
					_kioskPopup = new KioskSelectionPopupExt(curentPage, 
															_data,
															RobotScreen.DATA_RENTAL_CONFIRMRENTAL_KIOSKID,
															CssDefn.CSS_DATAENTRYPOPUP_CELLNUMBER,
															new HTML("<H2>select the kiosk you want to test."),_entryField);
					 //HB,2008/04/01, Step 4: add change listern,the third param is a widget have implements ChangeListener.
					_data.addValueChangeListener( RobotScreen.DATA_RENTAL_CONFIRMRENTAL_KIOSKID, _entryField );
		            _entryField.setMap(_parseKioskInfo.getKioskDescList());
					
					// Edit button
//					CommandPushButton kioskButton = new CommandPushButton( "select kiosk" );
//					kioskButton.setCommand( new SelectKioskCommand( _kioskPopup ));
					Button edit = new Button("select kiosk", new ClickListener(){
				    	  public void onClick(Widget sender){
				    		  new SelectKioskCommand( _kioskPopup ).execute();
				    	  }
				    });
					edit.setHTML("<font color=red> select kiosk </font>");
					grid.setWidget(grid.getRowCount()-2, grid.getColumnCount()-1, edit);
				}
			});
		}
   });
	
	
    
    
    
    container.add(grid);
   
}
	  
	  
	  
	  /**
	   * reset all related member of this page,excepting _instList and _instPanelList.
	   */
	  private void filterGroup(String group) {
		  if(group.equals(ROOT_NAME)){
			  _currentPage = _instList.size() > 0 ? 1 : 0;
			  _totalPage  = _instList.size() / PAGESIZE;
	   	      if( _totalPage * PAGESIZE < _instList.size() ){
	   	    	  _totalPage += 1;
	   	      }    
		  }
		  else {
			  int counter = 0; //a counter of group
			  for(Iterator insts = _instList.iterator(); insts.hasNext(); ) {
				  Instruction inst = (Instruction)insts.next();
				  if (inst.getGroup().equals(group)){
					  counter++;
				  }
			  }
			 
			  _currentPage = counter > 0 ? 1 : 0;
			  _totalPage   = counter / PAGESIZE;
	   	      if( _totalPage * PAGESIZE < counter ){
	   	    	  _totalPage += 1;
	   	      }  
			  
		  }
	  }
	  
	  /**
	   * 
	   * @param group
	   * @return : get all related panels
	   */
	  private ArrayList filteredInstPanel(String group){
		  
		  if(group.equals(ROOT_NAME)) {
			  return _instPanelList;
		  }
		  
		  ArrayList result = new ArrayList();
		  for(Iterator panels = _instPanelList.iterator();  panels.hasNext(); ) {
			  InstPanel panel = (InstPanel)panels.next();
			  if(panel.getInstruction().getGroup().equals(group)) {
				  result.add(panel);
			  }
		  }
		  return result;
	  }
	  
	  
	  
	  protected void setGroup(String group) {
		  _group = group;
		  filterGroup(group); 
	  }
	  
	  
	  
	  private class CancelIdleTimer extends Timer {
		  public void run(){
			  MainPanel.getInstance().haltIdleTimer();
		  }
	  }
	  
	  private class KioskSelectionPopupExt extends KioskSelectionPopup {
			
			public  KioskSelectionPopupExt(HasDataListeners listenerController,
					ScreenData       data,
					String           dataName,
					String           cssName,
					HTML             title,
					DataLabel        field){
				    super(listenerController,data,dataName,cssName,title,field);
					_listenerController.addValueListener(dataName, field);
				
			}
			
			
			
			public void onHide() {
		    	//get selected kiosk ip.
				String kioskId = _data.getValue(_dataName);
//				String kioskIp = (String)Security.getKioskIpList().get(kioskId);
				
				//for kiosk
				String kioskIp = (String)_parseKioskInfo.getKioskIpList().get(kioskId);
				if( kioskIp == null) {
					 kioskIp = LOCALHOST;
				}
				
				//for camera
				String cameraIp = (String)_parseKioskInfo.getCameraIpList().get(kioskId);
				if( cameraIp == null) {
					cameraIp = LOCALHOST;
				}
				
				
				_data.setValue(RobotScreen.DATA_ROBOTSCREEN_KIOSK_IP, kioskIp, null);
				
				//reset html source for ip-camera:video
				String htmlSource1 = HTMLTEMPLATE_VIDEO.replaceFirst("%h", cameraIp);
				htmlSource1 = htmlSource1.replaceFirst("%u", _parseKioskInfo.getUser());
				htmlSource1 = htmlSource1.replaceFirst("%p", _parseKioskInfo.getPassword());
//				if( kioskIp != LOCALHOST){
					_ipCameraVideo.setHTML(htmlSource1);  //it's no use for localhost????
//				}
				
//                //reset html source for ip-camera:control
//				String htmlSource2 = HTMLTEMPLATE_CONTROL.replaceFirst("%h", kioskIp);
//				htmlSource2 = htmlSource2.replaceFirst("%u", _parseKioskInfo.getUser());
//				htmlSource2 = htmlSource2.replaceFirst("%p", _parseKioskInfo.getPassword());
//				if( kioskIp != LOCALHOST){
//					_ipCameraControl.setHTML(htmlSource2);  //it's no use for localhost????
//				}
				
				
				
		    }
			
		}
	  
	  
	  
	  /*
	   * send the direction control instruction to ip-camera host or
	   * send the change brightness instruction to ip-camera host
	   */
	  private void directionPost(String host,String direction){
		  String htmlDirection = null;
		  htmlDirection = HTMLTEMPLATE_CONTROL.replaceFirst("%h", host);
		  htmlDirection = htmlDirection.replaceFirst("%u", _parseKioskInfo.getUser());
		  htmlDirection = htmlDirection.replaceFirst("%p", _parseKioskInfo.getPassword());
		  htmlDirection = htmlDirection.replaceFirst("%d", direction);
		  _ipCameraControl.setHTML(htmlDirection);
	  }
	  
	  /*
	   * send the home position instruction to ip-camera host
	   */
	  private void homePositionPost(String host){
		  String htmlDirection = "<iframe width= 0 height= 0 scrolling=\"no\" src=\"http://%u:%p@%h/nphControlCamera?Direction=HomePosition&Data=0&Resolution=320x240&Quality=Standard&RPeriod=65535&Size=STD&PresetOperation=Move&Language=0&Type=HomePosition"
           + "</iframe>"; //for reset homePosition
		  htmlDirection = htmlDirection.replaceFirst("%h", host);
		  htmlDirection = htmlDirection.replaceFirst("%u", _parseKioskInfo.getUser());
		  htmlDirection = htmlDirection.replaceFirst("%p", _parseKioskInfo.getPassword());
		  _ipCameraControl.setHTML(htmlDirection);
		  
	  }
	  
	  
	  //close current window....
	  public static native void closeWindow() /*-{
	    answer = confirm("Leave robot-test?")
		if (answer){
			$wnd.close(); 
		}
		else {
		
		}
   }-*/;
	  
	  
	  
	  
	  
	  

	  
	  
	  
	  
	  	
}
分享到:
评论

相关推荐

    H系列IPCamera手册

    "H系列IPCamera手册" 该手册主要介绍H系列IPCamera的使用方法和功能特点。下面是从手册中提炼出的关键知识点: 1. 产品概述:H系列IPCamera是一款网络摄像机,具有网络连接和远程访问功能,能实时监控和录像。 2....

    搜索局域网内IPCamera设备

    这样,其他类可以通过订阅此事件来处理接收到的IPCamera设备的信息,比如解析设备的IP地址、型号或其他元数据。 整个过程的核心在于使用UDP广播来搜索局域网内的IPCamera设备。通常,IPCamera设备会在启动时向网络...

    IPCamera使用手册

    IPCamera在安全监控、家庭自动化和商业应用中广泛应用,因其远程访问和实时监控的能力而受到青睐。 1. **产品概述** IPCamera是一种基于网络协议的摄像机,它将视频信号数字化并通过局域网(LAN)或广域网(WAN)...

    spydroid-ipcamera-master

    项目"spydroid-ipcamera-master"的实现涉及到Android系统的深度开发,包括但不限于: 1. **权限管理**:需要获取相机访问权限,以及可能的网络权限,以便进行视频流传输。 2. **硬件访问**:直接与Android设备的...

    spydroid-ipcamera-master.zip_Spydroid_ipcamera_java vlc_spydro

    spydroid-ipcamera是一个开源的andoird源码,运行在android手机上,可将手机的摄像头当做ipc camera,电脑可采用vlc实时监控手机的摄像头。

    emgu ipcamera demo.zip

    总结来说,"emgu ipcamera demo.zip"是一个实用的教程资源,展示了如何使用Emgu CV库和C#语言开发一个能够连接并显示IP摄像头实时流的应用。这个示例不仅对初学者理解计算机视觉和网络视频处理的概念有所帮助,也为...

    ipcamera网络摄像头安卓客户端源代码

    理解并掌握这些知识点,不仅有助于开发者构建自己的IPCamera客户端应用,也能提升他们在Android应用开发领域的专业技能。通过不断学习和实践,开发者可以在此基础上创新,打造出更加智能、高效的网络摄像头解决方案...

    ipcamera_ip_cam_

    它们通常连接到Wi-Fi或有线网络,允许用户通过互联网进行远程监控和录像。 2. **C++编程**: "main.cpp" 是C++编程中的主要入口点,通常包含了程序的初始化逻辑和主循环。这表明项目使用C++语言编写,且可能是一个...

    spydroid-ipcamera-master.zip

    "Spydroid"暗示了这个项目可能与监控或远程视频捕捉有关,而"ipcamera"则明确表示它涉及到IP网络摄像头技术。"master"通常指的是项目的主要分支,表明这是项目的完整版本,包含了所有最新的开发成果和改进。 该项目...

    ipcamera-for-android

    《Android手机变身IP Camera:利用“ipcamera-for-android”实现远程监控》 在现代科技的推动下,我们的生活越来越依赖于智能化设备。其中,IP Camera(网络摄像头)作为一种实时监控工具,广泛应用于家庭、办公室...

    spydroid-ipcamera 实现Android视频实时上传到服务器,服务器可以实时浏览

    vlc_2.2.4.0.exe是服务器的执行程序,安装时需要选择允许浏览器插件的选项,默认的就可以。spydroid-ipcamera是开源的项目,导入工程可以直接使用,运行后进入setting页面,需要勾选http port和Rtsp port二个选项。

    IPCamera的windows网络摄象头驱动

    IPCamera的windows网络摄象头驱动 配合andriod上面的软件(IP摄象头)可以把手机变成摄象头用。

    spydroid-ipcamera最新版源码

    通过对`spydroid-ipcamera`源码的深入研究,开发者不仅可以学习到Android摄像头编程的实践知识,还能了解到如何有效地利用硬件编码优化性能,这对于开发类似应用或进行相关研究具有极高的价值。同时,源码的开放性也...

    spydroid-ipcamera 8.0

    《Android IP摄像头应用:Spydroid IP Camera 8.0源码详解》 Spydroid IP Camera是一款专为Android设备设计的开源IP摄像头...在实践中不断探索,才能更好地理解和掌握这些技术,从而在自己的项目中发挥出更大的价值。

    android播放IPCamera的rtsp连接

    在Android平台上实现IP Camera的RTSP连接,是将网络摄像头的实时视频流通过RTSP(Real Time Streaming Protocol)协议传输到Android设备上进行播放的技术。本文将深入探讨这个主题,介绍相关的关键知识点,并以VLC ...

    IPcamera Test

    综上所述,【IPcamera Test】涉及到IP相机硬件性能、JPEG视频处理技术、网络通信、图像质量、延迟、控制接口、安全性和平台兼容性等多个方面的深度评估。通过这样的测试,可以确保IP camera在实际应用中能够稳定、...

    spydroid-ipCamera-ICamera AS导入不报错版本能运行版本

    解决AndroidStudio导入报错的各种问题,spydroid-ipCamera-ICamera,官方的 代码下载下来后,导入进AS IDE各种报错,弄了半天,各种库版本,不兼容问题。于是乎,自己新建了一个类似项目改版了代码,不会导入报错了。...

    spydroid-ipcamera这个项目能够将Android设备变成一个漂亮的网络摄像机.rar

    《将Android设备转化为网络摄像机:Spydroid-IPCamera项目详解》 在现代科技的浪潮中,Android设备已经无处不在,而将其利用到极致则成为开发者们不断追求的目标。"Spydroid-IPCamera"项目正是这样一个创新性的尝试...

    IPcamera38x38模块

    在实际应用中,用户可以根据自己的需求调整模块参数,例如图像质量、帧率、分辨率等,以适应不同场景的需求。同时,由于支持网络连接,该模块可以轻松地与云平台、智能家居系统或其他网络设备集成,实现远程监控和...

    IPcamera38*38模块

    标题中的“IPcamera38*38模块”指...综上所述,这个IPcamera38*38模块是一个集成了图像处理和网络通信功能的小型化设备,其设计和实现涉及到多个领域的专业知识,包括硬件设计、嵌入式软件开发、网络通信和安全技术等。

Global site tag (gtag.js) - Google Analytics