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

📄 jfpage.java

📁 用Java开发的、实现类似Visio功能的应用程序源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
   			layer	=(JFLayer)m_layerList.getByIndex(i);
   			if (layer.getVisible()){
   				layer.draw(g,isXorMode);
   			}
   		}catch(Exception e){
			m_logger.error("draw:"+e);   			
   		}
   	}
   }



   /** set if show or hide current object's design info
    */
   public void setShowDesign(boolean showDesign){ 
   	super.setShowDesign(showDesign);
   	
   	JFLayer layer;
   	for (int i=m_layerList.size()-1; i>=0; i--){
   		try{
   			layer	=(JFLayer)m_layerList.getByIndex(i);
   			layer.setShowDesign(showDesign);
   		}catch(Exception e){
   		}
   	}
   }


   /**
    *   pick up shape object by a position point.
    * 
    *   @param  g A graphics context used to pick some graphics sensitive shapes(e.g. label)
    *   @param  pnt A JFPoint that intersect or contained in an AbstractObject.
    *
    */ 	
   public AbstractObject  pickBy(Graphics g,JFPoint pnt){
   	return getCurrentLayer().pickBy(g,pnt);
   }
  	
   /**
    *   pick up shape object by a rectangle.
    * 
    *   @param  g A graphics context used to pick some graphics sensitive shapes(e.g. label)
    *   @param  rect A Rect that intersects or contains one or move AbstractObjects.
    *
    */ 	
   public ObjectList  pickBy(Graphics g,Rect rect){
   	return getCurrentLayer().pickBy(g,rect);
   }

   /**
    *   Get which port of current shape that intersects with point pnt.
    * 
    *   @param  pnt A JFPoint used to test intersection.
    *   @param  avoidParent A specified avoided parent to avoid connected to self.
    *   @return A port of current shape.
    *
    */ 	
   public Port  portIntersects(JFPoint pnt,AbstractObject avoidParent){
   	return getCurrentLayer().portIntersects(pnt,avoidParent);
   }

   /**
    *   Get a ports list of alls hapes that intersects with point pnt.
    * 
    *   @param  pnt A JFPoint used to test intersection.
    *
    *   @return A port list.
    *
    */ 	
   public List  portIntersectsList(JFPoint pnt){
        return getCurrentLayer().portIntersectsList(pnt);
   }

   /**
    *   Group a selection to one JFGroup object.
    * 
    *   @param objList a sub collection of this object list.
    *   @return A group object.
    */ 	
  public AbstractObject groupShapes(List objList){ 
  	return getCurrentLayer().groupShapes(objList,isShowDesign() && !isHidePorts());
  }

   /**
    *   Ungroup a selection to individual objects.
    * 
    *   @param objList a collection of grouped objects.
    *   @return An individual objects list.
    */ 	
  public List ungroupShapes(List objList){ 
  	return getCurrentLayer().ungroupShapes(objList);
 }             
   /**
    *   Clear access times, Clear all objects access times of current layer.
    */ 	
   public void clearAccessTimes(){
	getCurrentLayer().clearAccessTimes();   	
   }

    /** set zoom scale
     *  @param zoomScale A new zoom scale.
     */	
    public void setZoomScale(double zoomScale){
    	super.setZoomScale(zoomScale);
	m_layerList.setZoomScale(zoomScale);
	/*
   	JFLayer layer;
   	for (int i=m_layerList.size()-1; i>=0; i--){
   		try{
   			layer	=(JFLayer)m_layerList.getByIndex(i);
   			layer.setZoomScale(zoomScale);
   		}catch(Exception e){
   		}
   	}
   	*/
    }


    /** 
     *  bind ports at a specified point.
     *  @param mousePos Current mouse position.
     *  @return number of ports bound.
     */
    public int bindPorts(JFPoint mousePos){
    	return bindPorts(true,mousePos);
    }


    /** 
     *  unbind ports at a specified point.
     *  @param mousePos Current mouse position.
     *  @return number of ports unbound.
     */
    public int unbindPorts(JFPoint mousePos){
    	return bindPorts(false,mousePos);
    }

    /** 
     *  bind/unbind ports at a specified point.
     *  @param bind True if bind, false unbind.
     *  @param mousePos Current mouse position.
     *  @return number of ports bound/unbound.
     */
    private int bindPorts(boolean bind, JFPoint mousePos){
        List    l       =portIntersectsList(mousePos);
        if (l==null || l.size()==0)
        	return 0;
        	
	//clone a list for peer to peer attach/detach
	List newl       =new ArrayList(l);
	Iterator it     =l.iterator();
	while (it!=null && it.hasNext()){
		Port p  =(Port)it.next();
                                        
		Iterator newIt  =newl.iterator();
		while (newIt!=null && newIt.hasNext()){
			Port newp           =(Port)newIt.next();
			if (p!=newp){
				if (!bind){                      
					p.detachPort(newp);
				}else{
					//at least one parent is an open shape.        
					AbstractShape parent =(AbstractShape)p.getParent();
                                        AbstractShape newParent  =(AbstractShape)newp.getParent();
                                                
                                        if (parent.isOpenShape() || newParent.isOpenShape()){
                                                	p.attachPort(newp); 
                                                        JFPoint pnt     =p.getPortPoint();
                                                        JFPoint newPnt  =newp.getPortPoint();
                                                        
                                                        //adjust the port position concurrently.
                                                        if (!pnt.equals(newPnt,true)){
                                                        	if (newParent.isOpenShape())
                                                                	newParent.movePort(newp,pnt.getX(),pnt.getY());
                                                                else
                                                                	parent.movePort(p,newPnt.getX(),newPnt.getY());
                                                        }
					}  
				}
			}
		}
	}
	
	return l.size();
    }	


   /**
    *   Send a sub-collection of object list in current layer to back.
    * 
    *   @param objeList a sub collection of this object list.
    */ 	
  public void sendToBack(List objList){ 
        getCurrentLayer().sendToBack(objList);
  }

 	
   /**
    *   Send a sub-collection of object list in current layer to back.
    * 
    *   @param objeList a sub collection of this object list.
    */ 	
  public void bringToFront(List objList){
        getCurrentLayer().bringToFront(objList);
  }                 

   /**
    *   Insert a new layer to this page.
    * 
    *   @param layer A new layer
    *   @param index A index position for insertion. 
    */ 	
  public void insertLayer(JFLayer layer,int index){ 
  	if (layer.getObjectId()==0){
  		int objectId	=m_layerList.newObjectId();
  		layer.setObjectId(objectId);
  	}
  	
  	//create a new layer object list
  	ObjectList objList	=new ObjectList();
  	Iterator it	=m_layerList.getList().iterator();
  	int  layerIndex=0;
  	
	//add layers before the specified index position into new layer list
  	while (it!=null && it.hasNext() && layerIndex<index){
  		objList.getList().add(it.next());
  		layerIndex++;
  	}
  	
  	//add inserted layer
  	objList.add(layer);
  	
	//add layers fater the specified index position into new layer list
  	while (it!=null && it.hasNext()){
  		objList.getList().add(it.next()); 
  		layerIndex ++;
  	}
  	
  	//adjust index if it's invalid:
  	if (index>layerIndex)
  		index	=layerIndex;

	//relace the layer list.	
	m_layerList	=objList;  	
	setCurrentLayerIndex(index);  
	setShowDesign(false);
	if (!isHidePorts()){
		getCurrentLayer().setShowDesign(true);
	}
  }



   /**
    *   Add a new layer to this page.
    * 
    *   @param layer A new layer
    */ 	
  public void addLayer(JFLayer layer){ 
  	try{
		m_layerList.add(layer);
	}catch(Exception e){
	}
  } 

   /**
    *   Get a specified layer by index.
    * 
    *   @param index The index of a layer.
    */ 	
  public JFLayer getLayer(int index){ 
  	try{
		return (JFLayer)m_layerList.getByIndex(index);
	}catch(Exception e){
		return null;
	}
  } 

   /**
    *   Get a specified layer by object id.
    * 
    *   @param objectId The object id of a layer.
    */ 	
  public JFLayer getLayerByObjectId(int objectId){
  	try{
		return (JFLayer)m_layerList.getByObjectId(objectId);
	}catch(Exception e){
		return null;
	}
  } 


   /**
    *   Remove a specified layer.
    * 
    *   @param index The index of a layer.
    */ 	
  public void removeLayer(int index){
  	try{
		m_layerList.removeByIndex(index);
	}catch(Exception e){
	}
  } 
  
   /**
    *   Remove a specified layer.
    * 
    *   @param objId The object id of a layer.
    */ 	
  public void removeLayerByObjectId(int objectId){
  	try{
		m_layerList.removeByObjectId(objectId);
	}catch(Exception e){
	}
  } 
  
   /**
    *   Get layer items as check items, it's used to be modified by layer setup.
    *   @return A checkItem List.
    */ 	
   public List getLayerItemList(){
   	List itemList	=new ArrayList();
   	Iterator it	=m_layerList.getList().iterator();
   	while (it!=null && it.hasNext()){
   		JFLayer layer	=(JFLayer)it.next();
   		CheckItem checkItem	=new CheckItem();
   		checkItem.setId(layer.getObjectId());
   		checkItem.setLabel(layer.getName());
   		checkItem.setChecked(layer.getVisible());
   		checkItem.setObject(layer);
   		itemList.add(checkItem);
	}
	return itemList;
   }

   /**
    *   Restore layer items as item backuped in itemList.
    *   @param itemList A layer items list backuped.
    */ 	
   public void restoreLayerItemList(List itemList){
   	if (itemList==null || itemList.size()==0)
   		return;
   	m_layerList	=new ObjectList();
   	
   	Iterator it	=itemList.iterator();
   	int checkedIndex =-1;
   	int cnt=0;
   	try{
   		while (it!=null && it.hasNext()){
   			CheckItem checkItem	=(CheckItem)it.next();
   			JFLayer layer	=(JFLayer)checkItem.getObject();
   			layer.setObjectId(checkItem.getId());
   			layer.setName(checkItem.getLabel());
   			layer.setVisible(checkItem.getChecked());
   			m_layerList.add(layer);
   		
   			cnt++;
			if (checkItem.getChecked() && checkedIndex<0){
				//get the first checkedIndex
				checkedIndex	=cnt-1;
			}
		}
	
	}catch(Exception e){
	}

	setCurrentLayerIndex(checkedIndex);  
	setShowDesign(false);
	if (!isHidePorts()){
		getCurrentLayer().setShowDesign(true);
	}
   }


   /**
    *   Set new layer items 
    *   @param itemList item list that is modified
    *   @param removedItemList item list that is removed.
    */ 	
   public void setLayerItemList(List itemList, List removedItemList){
   	Iterator it;
   	CheckItem checkItem;
   	
   	//remove some existent layers
   	if (removedItemList!=null && removedItemList.size()>0){
   		it	=removedItemList.iterator();
   		while (it!=null && it.hasNext()){
   			checkItem	=(CheckItem)it.next();
   			//the id of a checkItem is actually the object id of a layer
   			//for some newly created checkItem, it will do nothing in removing.
   			removeLayerByObjectId(checkItem.getId());
   		}
   	}
	
	//update items   	
   	it	=itemList.iterator();
   	JFLayer layer;
   	try{
   		while (it!=null && it.hasNext()){
   			checkItem	=(CheckItem)it.next();
   			switch (checkItem.getState()){
   				case CheckItem.STATE_NEW:
   					layer	=new JFLayer();
   					layer.setObjectId(checkItem.getId());
   					layer.setName(checkItem.getLabel());
   					layer.setVisible(checkItem.getChecked());
   					m_layerList.add(layer);
   					break;
   				
   				default:
   					layer	=getLayerByObjectId(checkItem.getId());
   					layer.setName(checkItem.getLabel());
   					layer.setVisible(checkItem.getChecked());
   					break;
   			}
   		}
   	}catch(Exception e){
	}

	//re-order list items by the order of itemList	
	ObjectList newList	=new ObjectList();
	it	=itemList.iterator();
	int    checkedIndex	=-1; 
	int cnt=0;
	try{
		while (it!=null && it.hasNext()){
			checkItem	=(CheckItem)it.next();
			cnt++;
			if (checkItem.getChecked() && checkedIndex<0){
				//get the first checkedIndex
				checkedIndex	=cnt-1;
			}
			layer		=getLayerByObjectId(checkItem.getId());
			newList.add(layer);
		}	
	}catch(Exception e){
	}
	
	//replace the item list with a new one.
	m_layerList	=newList;
	setCurrentLayerIndex(checkedIndex);  
	setShowDesign(false);
	if (!isHidePorts()){
		getCurrentLayer().setShowDesign(true);
	}
   }


   /**
    *   Convert this object to String <br>
    * 
    *   @return  An string represents the content of the object
    *
    */ 	
   public String toString(){
   	StringBuffer buf=new StringBuffer();
	
	buf.append(super.toString());
   	buf.append("\n<page>\n");
   	buf.append("\nversion="+m_version);
   	buf.append("\nproducer="+m_producer);
   	buf.append("\nauthor="+m_author);
   	buf.append("\nmodified="+m_modified);
   	buf.append("\nhidePorts="+m_hidePorts);
   	buf.append("\ndisablePortSnapping="+m_disablePortSnapping);
   	buf.append("\nscaleValue="+m_scaleValue);
   	buf.append("\nscaleUnit="+m_scaleUnit);
   	buf.append("\nscreenUnit="+m_screenUnit);
   	buf.append(m_pageFormat.toString());
   	buf.append(m_canvasFormat.toString());
   	buf.append(m_layerList.toString());

   	return buf.toString();
   }


   /**
    *   Creates a new AbstractObject of the same class and with the same contents as this object.
    *   This method implements the method defined in AbstractObject.
    * 
    *   @return  A clone of this class.
    *
    */ 	
  protected AbstractObject cloneMe() throws CloneNotSupportedException{
  	return new JFPage();
  }
  
  
   /**
    *   Creates a new object of the same class and with the same contents as this object.
    * 
    *   @return  A clone of this instance.
    *
    */ 	
  public Object clone() throws CloneNotSupportedException{
  	try{

⌨️ 快捷键说明

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