📄 abstractlibrary.java
字号:
/**
* $Id:AbstractLibrary.java $
*
* Copyright 2004 ~ 2005 JingFei International Cooperation LTD. All rights reserved. *
*/
package com.jfimagine.jfgraph.shape.union;
import java.io.IOException;
import java.io.DataOutputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.DataInputStream;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.awt.Component;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Dimension;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.JPanel;
import com.jfimagine.jfgraph.shape.base.AbstractObject;
import com.jfimagine.jfgraph.shape.base.AbstractShape;
import com.jfimagine.jfgraph.shape.base.ObjectList;
import com.jfimagine.jfgraph.shape.base.ShapeConst;
import com.jfimagine.jfgraph.shape.base.JFVersion;
import com.jfimagine.jfgraph.shape.union.JFGroup;
import com.jfimagine.jfgraph.geom.JFPoint;
import com.jfimagine.jfgraph.geom.Rect;
import com.jfimagine.utils.commonutil.CommonUtil;
import com.jfimagine.utils.log.*;
/**
* AbstractLibrary class is used to store and recover customized graph libraries/templates.
*
* @author CookieMaker
*
* @version $Revision: 1.1.0 $
*/
public abstract class AbstractLibrary extends AbstractObject{
/**an internal log utility*/
private JFLogger m_logger=JFLogManager.getLogger(this.getClass());
/**
* library list.
* All of the library librarys within this library should store in this list.
*/
private ObjectList m_elemList =new ObjectList();
/** version */
private String m_version =JFVersion.getCurrentVersion();
/** producer */
private String m_producer =JFVersion.PRODUCER;
/** author */
private String m_author ="";
/**
* title of this library
*/
private String m_title ="library";
/**
* description of this library
*/
private String m_description ="";
/**
* filename of this library, this is a temporary file name that would not be stored.
*/
private String m_filename ="";
/**
* drawing element width
*/
protected int m_elemWidth =60;
/**
* if this library is modified.
*/
private boolean m_modified =false;
/**
* last picked library element
*/
private JFLibElem m_lastElem =null;
/**
* Get the version of this page.
*
* @return The version.
*
*/
public String getVersion(){
return m_version;
}
/**
* Get the producer of this page.
*
* @return The producer.
*
*/
public String getProducer(){
return m_producer;
}
/**
* Get the author of this page.
*
* @return The author.
*
*/
public String getAuthor(){
return m_author;
}
/**
* Set the author of this page.
*
* @param author A new author.
*
*/
public void setAuthor(String author){
if (author==null) author="";
m_author =author;
}
/**
* Get title of this library.
*/
public String getTitle(){
return m_title;
}
/**
* Set title of this library.
*/
public void setTitle(String title){
m_title =title;
}
/**
* Get description of this library.
*/
public String getDescription(){
return m_description;
}
/**
* Set description of this library.
*/
public void setDescription(String description){
m_description =description;
}
/**
* Get filename of this library.
*/
public String getFilename(){
return m_filename;
}
/**
* Set filename of this library.
*/
public void setFilename(String filename){
m_filename =filename;
}
/**
* Get the drawing element width.
*/
public int getElementWidth(){
return m_elemWidth;
}
/**
* Get library element list.
*/
public ObjectList getList(){
return m_elemList;
}
/**
* Add element
* @param elem Element to be added.
*/
public void add(JFLibElem elem){
try{
m_elemList.add(elem);
setModified(true);
m_lastElem =elem;
}catch(Exception e){
}
}
/**
* Remove element
* @param elem Element to be removed.
*/
public void remove(JFLibElem elem){
if (elem==null)
return;
removeByObjectId(elem.getObjectId());
}
/**
* Remove element by object id
* @param objId Object id.
*/
public void removeByObjectId(int objectId){
try{
m_elemList.removeByObjectId(objectId);
setModified(true);
m_lastElem =null;
}catch(Exception e){
}
}
/**
* Remove element by index
* @param index Object index.
*/
public void removeByIndex(int index){
try{
m_elemList.removeByIndex(index);
setModified(true);
m_lastElem =null;
}catch(Exception e){
}
}
/**
* if this page is modified.
*/
public boolean isModified(){
return m_modified;
}
/**
* set if this page is modified or unmodified(when save/load).
*/
public void setModified(boolean modified){
m_modified =modified;
}
/**
* to draw libraries on canvas, we need a proper draw size to force the canvas
* can show all library photos.
*
* @param initSize Initial size of the canvas.
* @return Actual size of canvas wanted.
*
*/
public Dimension getDrawSize(Dimension initSize){
int elemSize =m_elemList.size();
if (elemSize==0)
return new Dimension(initSize);
//initial size, width/height.
double width =initSize.getWidth();
double height =initSize.getHeight();
//library columns and rows on canvas.
int colCount =(int)Math.round(width/getElementWidth());
if (colCount<1) colCount =1;
int rowCount =elemSize/colCount;
if (elemSize % colCount>0) rowCount++;
//adjust the size of canvas to fit colCount and rowCount.
width =getElementWidth() * colCount;
height =getElementWidth() * rowCount;
if (width<initSize.getWidth())
width =initSize.getWidth();
if (height<initSize.getHeight())
height =initSize.getHeight();
return new Dimension((int)width,(int)height);
}
/**
* Draw current object on graphic canvas.
*
* @param g graphics context.
* @param width Width of the graphics context.
* @param height Height of the graphics context.
*
*/
public void draw(Graphics g,double width,double height){
int colCount =(int)Math.round(width/getElementWidth());
if (colCount<1) colCount =1;
int rowCount =(int)Math.round(height/getElementWidth());
if (rowCount<1) rowCount =1;
int col=1;
int row=1;
g.setColor(new Color(230,230,230));
//draw background grids
for (col=1; col<colCount; col++){
int x =(int)(col*getElementWidth());
g.drawLine(x,0,x,(int)height);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -