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

📄 abstractlibrary.java

📁 用Java开发的、实现类似Visio功能的应用程序源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	}	
	for (row=1; row<rowCount; row++){
		int y	=(int)(row*getElementWidth());
		g.drawLine(0,y,(int)width,y);
	}	
	
	
	//draw actual elements
	col=1;
	row=1;
	Rect drawRegion	=new Rect();
   	JFLibElem  elem;
   	Iterator it	=m_elemList.getList().iterator();
   	while (it!=null && it.hasNext()){
   		if (col>colCount){
   			row++;
   			col=1;
   		}
   		double xOffset	=(col-1) * getElementWidth();
   		double yOffset  =(row-1) * getElementWidth();

   		drawRegion.setValue(xOffset,yOffset,getElementWidth(),getElementWidth());
   		
		elem	=(JFLibElem)it.next();
		elem.draw(g,drawRegion);

		col++;
   	}
   	
   	if (m_lastElem!=null)
   		m_lastElem.drawPicked(g);
   }


   /**
    *   draw a picked sign around current library library.
    * 
    *   @param  g A graphics context used to pick one library.
    *   @param  pnt A JFPoint that intersect or contained in an library.
    *
    */ 	
   public void  drawPicked(Graphics g,JFPoint pnt){
   	JFLibElem elem	=pickBy(pnt);
   	if (elem!=null){
   		elem.drawPicked(g);
   	}
   }


   /**
    *   pick up library by a position point.
    * 
    *   @param  pnt A JFPoint that intersect or contained in an library.
    *
    */ 	
   public JFLibElem  pickBy(JFPoint pnt){
   	m_lastElem	=null;
   	JFLibElem elem;
   	
   	Iterator it	=m_elemList.getList().iterator();
   	while (it!=null && it.hasNext()){
   		elem	=(JFLibElem)it.next();
   		if (elem.intersects(pnt)){
   			m_lastElem	=elem;
   			return elem;
   		}
   	}
   	
   	return null;
   }

   /**
    *  get last picked library element
    */
   public JFLibElem getLastPicked(){
   	return m_lastElem;
   }


   /**
    *   Convert this object to String <br>
    * 
    *   @return  An string represents the content of the object
    *
    */ 	
   public String toString(){
   	StringBuffer buf=new StringBuffer();
	
	buf.append("\ntitle=");		buf.append(m_title); buf.append(";");
	buf.append("description=");	buf.append(m_description); buf.append(";");
   	buf.append("\n<Element list>\n");
	buf.append(m_elemList.toString());

   	return buf.toString();
   }

 
  
   /**
    *   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;
  		}
  		
  		AbstractLibrary lib =(AbstractLibrary) obj;
  		lib.m_elemList	=(ObjectList)m_elemList.clone();
  		lib.m_title	=m_title;
  		lib.m_description =m_description;
  		
  		return lib;
  		
	}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_elemList.hashCode() ^ 
  		m_title.hashCode() ^
  		m_description.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 AbstractLibrary))
            return false;

      AbstractLibrary  lib= (AbstractLibrary)obj;
      
      return  	(lib.m_elemList.equals(m_elemList) &&
      	         lib.m_title.equals(m_title) &&
      	         lib.m_description.equals(m_description));
  }

   /**
    *   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{
  
	//write a leading key here, to indicate current page version is equal or great than 1.8.0.
	stream.writeInt(JFVersion.LEADINGKEY_180);
	
	super.saveToStream(stream,version);

	stream.writeUTF(JFVersion.getCurrentVersion());

	stream.writeUTF(m_producer);
	stream.writeUTF(m_author);
    	
	m_elemList.saveToStream(stream,version);
	stream.writeUTF(m_title);
	stream.writeUTF(m_description);
  }

   /**
    *   Load this library from a binary file.
    * 
    *   @param fileName A file name.
    *   @param c A component used to help loading some special objects, e.g. image.
    *
    */ 	
    public boolean loadFromBinary(String fileName,Component c){
	
	try{

		InputStream in;
		if (CommonUtil.isURLFile(fileName)){
			//java.net.URL url	=new java.net.URL(fileName);
			//in	=url.openStream();
			in	=com.jfimagine.utils.io.DownloadURLFile.openDownloadStream(fileName);			
		}else{
          		in=new FileInputStream(fileName);
            	}

		DataInputStream dataInput=new DataInputStream(new BufferedInputStream(in));
		com.jfimagine.utils.io.JFReader reader	=new com.jfimagine.utils.io.JFBinaryReader(dataInput);

            	loadFromStream(reader,false,null); 

            	if (c!=null)
              		finishLoadingImages(c);

		in.close();
		return true;
	}catch(Exception e){
		m_logger.error("loadFromBinary: "+e);
		return false;
	}
    }


   /**
    *   Save this page to a binary file.
    * 
    *   @param fileName A file name.
    *
    */ 	
    public boolean saveToBinary(String fileName){

	try{
		//binary JFDraw file
		DataOutputStream out =
        		new DataOutputStream(
        			new BufferedOutputStream(
        				new FileOutputStream(fileName)));

		com.jfimagine.utils.io.JFWriter writer	=new com.jfimagine.utils.io.JFBinaryWriter(out);
        
        	saveToStream(writer,null);
		out.close();

		setModified(false);
		
		return true;
	}catch(Exception e){
		m_logger.error("saveToBinary: "+e);
		return false;
	}
    }


   /**
    *   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{

  	//detect if a leading key is stored at the top of the page.
  	int leadingKey	=stream.readInt();

  	
  	if (leadingKey==JFVersion.LEADINGKEY_180){
		//the leading key is assigned, so create a temporary version object		
		version	=new JFVersion(JFVersion.VERSIONID_180);

	}else{
  		//the leading key is not assigned, so it's actually an object type now:
  		setObjectType(leadingKey);
  		skipHead	=true;

	}

	super.loadFromStream(stream,skipHead,version);

	m_version	=stream.readUTF();

	m_producer	=stream.readUTF();

	m_author	=stream.readUTF();		    	

        /** create a JFVersion object by current version,for version control on file formats*/	      
        version		=new JFVersion(m_version);

	m_elemList.loadFromStream(stream,false,version);//don't skip head here
	m_title		=stream.readUTF();

	m_description	=stream.readUTF();
  }

  
   /**
    *   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){	
  	Iterator it	=m_elemList.getList().iterator();
  	while (it!=null && it.hasNext()){
  		JFLibElem elem	=(JFLibElem)it.next();
  		elem.finishLoadingImages(canvas);
	}
	
	return true;
  }

 

 }

⌨️ 快捷键说明

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