📄 jfpage.java
字号:
/**
* $Id:JFPage.java $
*
* Copyright 2004 ~ 2005 JingFei International Cooperation LTD. All rights reserved. *
*/
package com.jfimagine.jfgraph.shape.union;
import java.net.URL;
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.Graphics;
import java.awt.Graphics2D;
import java.awt.Color;
import java.awt.Component;
import java.awt.image.BufferedImage;
import java.awt.Dimension;
import java.awt.RenderingHints;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import com.jfimagine.jfdom.Document;
import com.jfimagine.jfdom.Element;
import com.jfimagine.jfdom.XMLOutput;
import com.jfimagine.jfdom.XMLInput;
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.Port;
import com.jfimagine.jfgraph.shape.base.ShapeConst;
import com.jfimagine.jfgraph.shape.base.JFVersion;
import com.jfimagine.jfgraph.shape.union.JFLayer;
import com.jfimagine.jfgraph.shape.union.CheckItem;
import com.jfimagine.jfgraph.shape.decorate.JFPageFormat;
import com.jfimagine.jfgraph.shape.decorate.CanvasFormat;
import com.jfimagine.jfgraph.geom.JFPoint;
import com.jfimagine.jfgraph.geom.Rect;
import com.jfimagine.utils.commonutil.CommonUtil;
import com.jfimagine.utils.log.*;
/**
* JFPage class.
* A page is a cad page, for multi-views of a cad graph design.
*
* @author CookieMaker
*
* @version $Revision: 1.00 $
*/
public class JFPage extends AbstractObject{
/** A XML string tag represents a JFDraw xml file */
public static final String XML_JFDRAW ="JFDraw";
/** A XML string tag represents a Page */
public static final String XML_PAGE ="Page";
/** A XML string tag represents if hide or show ports */
public static final String XML_HIDEPORTS ="hidePorts";
/** A XML string tag represents if disable or enable port snapping */
public static final String XML_DISABLEPORTSNAPPING ="disablePortSnapping";
/** A XML string tag represents a scale value */
public static final String XML_SCALEVALUE ="scaleValue";
/** A XML string tag represents a scale unit */
public static final String XML_SCALEUNIT ="scaleUnit";
/** A XML string tag represents a screen unit */
public static final String XML_SCREENUNIT ="screenUnit";
/**an internal log utility*/
private JFLogger m_logger=JFLogManager.getLogger(this.getClass());
/**
* layer list.
* All of the layers within this page should store in this list.
*/
private ObjectList m_layerList =new ObjectList();
/** version */
private String m_version =JFVersion.getCurrentVersion();
/** producer */
private String m_producer =JFVersion.PRODUCER;
/** author */
private String m_author ="";
/** page format */
private JFPageFormat m_pageFormat =new JFPageFormat();
/** canvas format */
private CanvasFormat m_canvasFormat =new CanvasFormat();
/**
* Current layer index.
*/
private int m_currentLayerIndex =0;
/**
* if this page is modified.
*/
private boolean m_modified =false;
/**
* Hide ports
*/
private boolean m_hidePorts =false;
/**
* Disable port snapping
*/
private boolean m_disablePortSnapping=false;
/**
* Scale value, e.g. 1cm = [scaleValue] * km
*/
private double m_scaleValue =1;
/**
* Scale units, e.g. 1cm = 100 * [scaleUnit]
*/
private int m_scaleUnit =ShapeConst.MEASURE_TYPE_IN;
/**
* Screen unit, e.g. 1 * [screenUnit] = 1000 * meter
*/
private int m_screenUnit =ShapeConst.MEASURE_TYPE_IN;
/**
* Constructor for Page
*/
public JFPage(){
setObjectType(ShapeConst.OBJECTTYPE_PAGE);
setXMLTag(XML_PAGE);
//add a default layer.
try{
m_layerList.add(new JFLayer());
}catch(Exception e){
}
}
/**
* clear all data in this page, to create a complete new page.
*/
public void newPage(){
try{
m_layerList.clear();
m_layerList.add(new JFLayer());
}catch(Exception e){
}
}
/**
* 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;
}
/**
* 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;
}
/**
* if assigned hidding ports .
*/
public boolean isHidePorts(){
return m_hidePorts;
}
/**
* set if hide or show ports.
*/
public void setHidePorts(boolean hide){
m_hidePorts =hide;
JFLayer layer =getCurrentLayer();
if (layer!=null){
layer.setShowDesign(!hide);
}
}
/**
* if assigned disable port snapping.
*/
public boolean isDisablePortSnapping(){
return m_disablePortSnapping;
}
/**
* set if hide or show ports.
*/
public void setDisablePortSnapping(boolean disable){
m_disablePortSnapping =disable;
}
/**
* Get the scale value, a scale value is something like << 1cm = [scaleValue] * km >>
* @return the scale value.
*/
public double getScaleValue(){
return m_scaleValue;
}
/**
* Set the scale value
* @param scale A new scale value
*/
public void setScaleValue(double scale){
m_scaleValue =scale;
}
/**
* Get the scale unit, a scale unit is something like << 1cm = 100 * [scaleUnit] >>
* @return the scale unit.
*/
public int getScaleUnit(){
return m_scaleUnit;
}
/**
* Set the scale unit
* @param unit A new scale unit
*/
public void setScaleUnit(int unit){
m_scaleUnit =unit;
}
/**
* Get the screen unit, a screen unit is something like << 1 * [screenUnit] = 1000 * meter >>
* We only allowed CM or INch for current screen unit.
* @return the screen unit.
*/
public int getScreenUnit(){
return m_screenUnit;
}
/**
* Set the screen unit
* We only allowed CM or INch for current screen unit.
* @param unit A new screen unit
*/
public void setScreenUnit(int unit){
m_screenUnit =unit;
}
/** set scale as metric or english measurement.
* if the scale units has been modified before, and a scaleUnit is different as a screenUnit,
* there would be no effects with this method.
* @param isMetric True if is metric, false english.
*/
public void setIsMetric(boolean isMetric){
if (m_scaleUnit==m_screenUnit){
if (isMetric){
m_scaleUnit =ShapeConst.MEASURE_TYPE_CM;
m_screenUnit =ShapeConst.MEASURE_TYPE_CM;
}else{
m_scaleUnit =ShapeConst.MEASURE_TYPE_IN;
m_screenUnit =ShapeConst.MEASURE_TYPE_IN;
}
}
}
/**
* Get the shape list.
*
* @return The shape list.
*
*/
public ObjectList getLayerList(){
return m_layerList;
}
/**
* Get page format.
*
* @return The page format.
*
*/
public JFPageFormat getPageFormat(){
return m_pageFormat;
}
/**
* Get canvas format.
*
* @return The canvas format.
*
*/
public CanvasFormat getCanvasFormat(){
return m_canvasFormat;
}
/**
* Get the bounds of this page.
*
* @return The bounds rectangle.
*
*/
public Rect getBounds(){
double minx=0,miny=0,maxx=0,maxy=0;
Iterator it =m_layerList.getList().iterator();
while (it!=null && it.hasNext()){
Rect bounds =((JFLayer)it.next()).getBounds();
minx =Math.min(minx,bounds.getX());
miny =Math.min(miny,bounds.getY());
maxx =Math.max(maxx,bounds.getX()+bounds.getWidth());
maxy =Math.max(maxy,bounds.getY()+bounds.getHeight());
}
if (minx>maxx) minx=maxx;
if (miny>maxy) miny=maxy;
return new Rect(minx,miny,maxx-minx,maxy-miny);
}
/**
* Get the current layer.
*
* @return The current layer.
*
*/
public JFLayer getCurrentLayer(){
if (m_currentLayerIndex>=0 && m_currentLayerIndex<m_layerList.size()){
return (JFLayer)m_layerList.getByIndex(m_currentLayerIndex);
}else{
return null;
}
}
/**
* Get the current layer index.
*
* @return The current layer index.
*
*/
public int getCurrentLayerIndex(){
return m_currentLayerIndex;
}
/**
* Set the current layer index.
*
* @param layer A new layer index.
*
*/
public void setCurrentLayerIndex(int layerIndex){
m_currentLayerIndex =layerIndex;
}
/**
* Consider the default visible layer, then set current layer index on it.
*
*/
public void setDefaultLayerIndex(){
setShowDesign(false);
JFLayer layer;
for (int i=0; i<m_layerList.size(); i++){
try{
layer =(JFLayer)m_layerList.getByIndex(i);
if (layer.getVisible()){
m_currentLayerIndex =i;
if (!isHidePorts()){
layer.setShowDesign(true);
}
break;
}
}catch(Exception e){
}
}
}
/**
* Set value by a new object.
*
* @param object A new object
*
*/
public void setValue(AbstractObject obj){
super.setValue(obj);
if (obj==null || !(obj instanceof JFPage))
return;
JFPage page =(JFPage)obj;
m_layerList =page.m_layerList;
m_version =page.m_version;
m_producer =page.m_producer;
m_author =page.m_author;
m_pageFormat.setPageFormat(page.m_pageFormat.getPageFormat());
m_canvasFormat.setValue(page.m_canvasFormat);
m_currentLayerIndex =page.m_currentLayerIndex;
m_modified =page.m_modified;
m_hidePorts =page.m_hidePorts;
m_disablePortSnapping=page.m_disablePortSnapping;
m_scaleValue =page.m_scaleValue;
m_scaleUnit =page.m_scaleUnit;
m_screenUnit =page.m_screenUnit;
}
/**
* Draw current page on graphic canvas.
*
* @param g A graphic canvas.
* @param isXorMode If is in xor mode now.
*
*/
public void draw(Graphics g,boolean isXorMode){
if (g==null)
return;
JFLayer layer;
for (int i=m_layerList.size()-1; i>=0; i--){
try{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -