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

📄 jflayer.java

📁 用Java开发的、实现类似Visio功能的应用程序源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
  	if (objList==null || objList.size()<=1)
  		return null;

  	JFGroup g	=new JFGroup();
  	g.setObjectId(m_shapeList.newObjectId());
	
	boolean   disableScaling		=true;
	boolean   disableModifyingProperties    =true;
	boolean   disableMotion			=true;
	
	//add objList into this new group object,remove the reference in m_shapeList.
  	Iterator it	=objList.iterator();
  	while (it!=null && it.hasNext()){
  		try{
  			AbstractObject obj	=(AbstractObject)it.next(); 
  				
  			g.getList().add(obj);
  			AbstractShape shape	=(AbstractShape)obj;
  			
  			//read shape settings
  			if (!shape.isDisableScaling())  disableScaling	=false;
  			if (!shape.isDisableModifyingProperties()) disableModifyingProperties	=false;
  			if (!shape.isDisableMotion())   disableMotion	=false;
  			
  			m_shapeList.removeByObjectId(obj.getObjectId());
  		}catch(Exception e){
  			m_logger.error("groupShapes: "+e);
  		}
	}

	//set shape settings
	g.setDisableScaling(disableScaling);
	g.setDisableModifyingProperties(disableModifyingProperties);
	g.setDisableMotion(disableMotion);
	
  	g.setShowDesign(showDesign);

	
	try{    
		//结束Group的制作 
		g.finishDrawing();
		m_shapeList.add(g); 
		return g;
	}catch(Exception e){
  		m_logger.error("groupShapes1: "+e);
	}
	return null;
  }

   /**
    *   Ungroup a selection to individual objects.
    * 
    *   @param objList a collection of grouped objects.
    *   @return An individual objects list.
    */ 	
  public List ungroupShapes(List objList){      
  	List ret	=new ArrayList();
  	if (objList==null || objList.size()==0)
  		return ret;
  	
	//add objList into this new group object,remove the reference in m_shapeList.
  	Iterator it	=objList.iterator();
  	while (it!=null && it.hasNext()){
  		try{
  			AbstractObject obj	=(AbstractObject)it.next();
  			if (obj instanceof JFGroup){
  				JFGroup g	=(JFGroup)obj;
  				//add the sub collection of this group into return list
  				ret.addAll(g.getList().getList());  
  				//extract the sub collection back to main shape list
  				m_shapeList.getList().addAll(g.getList().getList());
  				//remove this group from main shape list.
  				m_shapeList.removeByObjectId(g.getObjectId());
  				
  			}else{
  				ret.add(obj);
  			}
  		}catch(Exception e){
			m_logger.error("ungroupShapes :"+e);
  		}
	}
	
	return ret;
  }



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

   /**
    *   Send a sub-collection of this object list to front.
    * 
    *   @param objeList a sub collection of this object list.
    */ 	
  public void bringToFront(List objList){
        m_shapeList.bringToFront(objList);
  }                 

   /**
    *   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<layer>\n");
   	buf.append(m_shapeList.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 JFLayer();
  }
  
  
   /**
    *   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{
  		Object obj =super.clone();
  		if (obj==null){
  			return null;
  		}
  		
  		JFLayer layer =(JFLayer) obj;
  		layer.m_shapeList    	=(ObjectList)m_shapeList.clone();  
  		layer.m_visible		=m_visible;
  		
  		return layer;
  		
	}catch(Exception e){
		throw new CloneNotSupportedException(e.getMessage());
	}
  }


   /**
    *   Returns the hashcode for this Object.
    * 
    *   @return hash code for this Point2D.
    *
    */ 	
  public int hashCode(){
       	
  	return  super.hashCode() ^
  		m_shapeList.hashCode();
  }


   /**
    *   Determines whether or not two objects are equal. 
    * 
    * 	@param obj  an object to be compared with this object 
    * 
    *   @return true if the object to be compared is an instance of Port and has the same values; false otherwise.
    *
    */ 	
  public boolean equals(Object obj){
      if (!super.equals(obj))
             return false;
             		
      if (obj == this)
             return true;
      if (!(obj instanceof JFLayer))
            return false;

      JFLayer  layer= (JFLayer)obj;
      
      return  	(layer.m_shapeList.equals(m_shapeList));
  }


   /**
    *   Append necessary xml child for current element,
    *   this method will be called internally by toDOM.
    * 
    *   @param  element A XML element to append child xml nodes
    *   @param  version A file version notification so this object can obey the rules to save data.
    *
    */ 	
  protected void appendChildToDOM(Element element,JFVersion version){
  	if (element==null)
  		return;
  			
  	super.appendChildToDOM(element,version);

    	m_shapeList.toDOM(element,version);
    	element.addChild(new Element(XML_VISIBLE,m_visible?"1":"0"));
   		
  }


   /**
    *   Extract needed xml child from current element,
    *   this method will be called internally by fromDOM.
    * 
    *   @param  element An element used to extract needed xml child
    *   @param  version A file version notification so this object can obey the rules to fetch data.
    *
    */ 	
  protected void extractChildFromDOM(Element element,JFVersion version){

      	if (element==null)
  	  	return;
  
      	super.extractChildFromDOM(element,version);
      	  
      	m_shapeList.fromDOM(element.getChild(m_shapeList.getXMLTag()),version);
      	m_visible	=Element.getBooleanValue(element.getChild(XML_VISIBLE));
      	
      	if (version.lowerVersionOf(JFVersion.VERSIONID_180)){
      		String name		=Element.getStringValue(element.getChild(XML_NAME));
      		setName(name);
      	}

      	attachRealPort();
  }

 
   /**
    *   Save this object to a binary stream 
    * 
    *   @param stream An binary output stream
    *   @param  version A file version notification so this object can obey the rules to save data.
    *
    *   @exception  java.io.IOException
    *
    */ 	
  public void saveToStream(com.jfimagine.utils.io.JFWriter stream,JFVersion version) throws IOException{
	    super.saveToStream(stream,version);
	    	
	    m_shapeList.saveToStream(stream,version);
	    stream.writeBoolean(m_visible);
  }

   /**
    *   Load object data from a binary stream <br>
    * 
    *   @param stream An binary input stream
    *
    *   @param skipHead Skip head 'TYPE' check, an shape object should always 
    *   has its own shape-type stored, if this shape-type has already been readed,
    *   this loadFromStream should/could not read the type anymore.
    *
    *   @param  version A file version notification so this object can obey the rules to fetch data.
    *   @exception  java.io.IOException
    *
    */ 	
  public void loadFromStream(com.jfimagine.utils.io.JFReader stream,boolean skipHead,JFVersion version) throws IOException{
	super.loadFromStream(stream,skipHead,version);
	   	
	m_shapeList.loadFromStream(stream,false,version);//don't skip head here
	m_visible	=stream.readBoolean();

      	if (version.lowerVersionOf(JFVersion.VERSIONID_180)){
		String name		=stream.readUTF();
		setName(name);
	}
	attachRealPort();
		
  }

  
   /**
    *   for loading an image, we need to call this finish loading image method to completely create a new image.
    * 
    *   @param canvas A component for creating an image object.
    */
  public boolean finishLoadingImages(java.awt.Component canvas){	
	return JFImage.finishLoadingImages(m_shapeList,canvas);
  }

  
   /**
    *   A loadFromStream method should only load an parentId-objectId list of ports attached,
    *   So here we use an attachRealPort to ACTUALLY attach some ports to the ports in list.
    * 
    *   @param shapeList  A shapeList used to pick out their ports for ports' attached list
    *
    */ 	
  public void attachRealPort(){
  	m_shapeList.attachRealPort();
  }


 }

⌨️ 快捷键说明

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