📄 jfgroup.java
字号:
return;
basePoint =new JFPoint(basePoint.getX(), basePoint.getY());
refPoint1 =new JFPoint(refPoint1.getX(), refPoint1.getY());
refPoint2 =new JFPoint(refPoint2.getX(), refPoint2.getY());
Iterator it =m_objList.getList().iterator();
while (it!=null && it.hasNext()){
AbstractShape aShape =(AbstractShape)it.next();
aShape.scaleBy(basePoint,refPoint1,refPoint2,scale);
}
}
/**
* Scale current object by specified points and scale percent.
* We only support a concurrent width-height scale here, suppose width as the length from
* basePoint to refPoint1, height as the length from basePoint to refPoint2, and
* one scale percent acts on both width and height.
*
* @param basePoint A base point that is unmovable.
* @param refPoint1 A 'width' reference point.
* @param refPoint2 A 'height' reference point.
* @param scale A reference scale percent.
*
*/
public void scaleBy(JFPoint basePoint, JFPoint refPoint1, JFPoint refPoint2, double scale){
startMoveLabel();
m_rect.scaleBy(basePoint,refPoint1,refPoint2,scale);
initNodes();
finishMoveLabel();
Iterator it =m_objList.getList().iterator();
while (it!=null && it.hasNext()){
AbstractShape aShape =(AbstractShape)it.next();
aShape.scaleBy(basePoint,refPoint1,refPoint2,scale);
}
}
/**
* Scale current object by a specified x and y scale.<br>
* This is a special scale method used to scale a shape in arbitrary x and y scale.<br>
* Please see AbstractShape.scaleBy for detailed description.
*
* @param basePoint A base scale point for scaling reference.
* @param xScale A scale percentage in x coordinate, default to 1.0
* @param yScale A scale percentage in y coordinate, default to 1.0
*
*/
public void scaleBy(JFPoint basePoint,double xScale, double yScale){
startMoveLabel();
m_rect.scaleBy(basePoint,xScale,yScale);
initNodes();
finishMoveLabel();
Iterator it =m_objList.getList().iterator();
while (it!=null && it.hasNext()){
AbstractShape aShape =(AbstractShape)it.next();
aShape.scaleBy(basePoint,xScale,yScale);
}
}
/**
* Move current object by an x and y offset.
*
* @param x, y Moving offsets.
*
*/
public void moveBy(double x, double y){
m_rect.moveBy(x,y);
m_label.moveBy(x,y);
initNodes();
Iterator it =m_objList.getList().iterator();
while (it!=null && it.hasNext()){
AbstractShape aShape =(AbstractShape)it.next();
aShape.moveBy(x,y);
}
}
/**
* Rotate this group by an angle theta.
*
* @param theta A rotate angle.
*
*/
public void rotateBy(double theta){
JFPoint center =m_rect.getCenter();
rotateBy(center.getX(),center.getY(),theta);
}
/**
* Rotate this line by a specified point and an angle theta.
*
* @param baseX, baseY A rotate center coordinates.
*
* @param theta A rotate angle.
*
*/
public void rotateBy(double baseX,double baseY, double theta){
startMoveLabel();
m_rect.rotateBy(baseX,baseY,theta);
initNodes();
finishMoveLabel();
Iterator it =m_objList.getList().iterator();
while (it!=null && it.hasNext()){
AbstractShape aShape =(AbstractShape)it.next();
aShape.rotateBy(baseX,baseY,theta);
}
}
/**
* Mirror this group by a central x coordinate of this group. We make a left-right flip here.
*/
public void mirrorBy(){
JFPoint center =m_rect.getCenter();
mirrorBy(center.getX());
}
/**
* Mirror this group by a x coordinate. We make a left-right mirror here.
*
* @param baseX A mirror base x coordinate.
*
*/
public void mirrorBy(double baseX){
startMoveLabel();
m_rect.mirrorBy(baseX);
initNodes();
finishMoveLabel();
Iterator it =m_objList.getList().iterator();
while (it!=null && it.hasNext()){
AbstractShape aShape =(AbstractShape)it.next();
aShape.mirrorBy(baseX);
}
}
/**
* Reverse this group by a central y coordinate of this group. We make a up-down flip here.
*/
public void flipBy(){
JFPoint center =m_rect.getCenter();
flipBy(center.getY());
}
/**
* Reverse this group by a y coordinate. We make a up-down flip here.
*
* @param baseY A flip base y coordinate.
*
*/
public void flipBy(double baseY){
startMoveLabel();
m_rect.flipBy(baseY);
initNodes();
finishMoveLabel();
Iterator it =m_objList.getList().iterator();
while (it!=null && it.hasNext()){
AbstractShape aShape =(AbstractShape)it.next();
aShape.flipBy(baseY);
}
}
/**
* 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(m_rect.toString());
buf.append(m_objList.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 JFGroup();
}
/**
* 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;
}
JFGroup g =(JFGroup) obj;
g.m_rect.setValue(this.m_rect);
Iterator it =m_objList.getList().iterator();
while (it!=null && it.hasNext()){
AbstractShape aShape =(AbstractShape)it.next();
g.m_objList.add((AbstractObject)aShape.clone());
}
return g;
}catch(Exception e){
throw new CloneNotSupportedException(e.getMessage());
}
}
/**
* Returns the hashcode for this Object.
*
* @return hash code for this Point2D.
*
*/
public int hashCode(){
int code =super.hashCode() ^
m_rect.hashCode();
Iterator it =m_objList.getList().iterator();
while (it!=null && it.hasNext()){
AbstractShape aShape =(AbstractShape)it.next();
code ^=aShape.hashCode();
}
return code;
}
/**
* 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 JFGroup))
return false;
JFGroup g =(JFGroup)obj;
return m_rect.equals(g.m_rect) &&
m_objList.equals(g.m_objList);
}
/**
* 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);
//append m_rect to dom.
JFPoint pnt;
pnt =m_rect.getVertex(Rect.VERTEXTYPE_LEFTTOP);
element.addChild(new Element(AbstractRectangle.XML_LEFTTOPX, pnt.getX()));
element.addChild(new Element(AbstractRectangle.XML_LEFTTOPY, pnt.getY()));
pnt =m_rect.getVertex(Rect.VERTEXTYPE_RIGHTTOP);
element.addChild(new Element(AbstractRectangle.XML_RIGHTTOPX, pnt.getX()));
element.addChild(new Element(AbstractRectangle.XML_RIGHTTOPY, pnt.getY()));
pnt =m_rect.getVertex(Rect.VERTEXTYPE_LEFTBOTTOM);
element.addChild(new Element(AbstractRectangle.XML_LEFTBOTTOMX, pnt.getX()));
element.addChild(new Element(AbstractRectangle.XML_LEFTBOTTOMY, pnt.getY()));
pnt =m_rect.getVertex(Rect.VERTEXTYPE_RIGHTBOTTOM);
element.addChild(new Element(AbstractRectangle.XML_RIGHTBOTTOMX, pnt.getX()));
element.addChild(new Element(AbstractRectangle.XML_RIGHTBOTTOMY, pnt.getY()));
m_objList.toDOM(element,version);
}
/**
* 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);
double x=0,y=0;
x =Element.getDoubleValue(element.getChild(AbstractRectangle.XML_LEFTTOPX));
y =Element.getDoubleValue(element.getChild(AbstractRectangle.XML_LEFTTOPY));
m_rect.getVertex(Rect.VERTEXTYPE_LEFTTOP).setValue(x,y);
x =Element.getDoubleValue(element.getChild(AbstractRectangle.XML_RIGHTTOPX));
y =Element.getDoubleValue(element.getChild(AbstractRectangle.XML_RIGHTTOPY));
m_rect.getVertex(Rect.VERTEXTYPE_RIGHTTOP).setValue(x,y);
x =Element.getDoubleValue(element.getChild(AbstractRectangle.XML_LEFTBOTTOMX));
y =Element.getDoubleValue(element.getChild(AbstractRectangle.XML_LEFTBOTTOMY));
m_rect.getVertex(Rect.VERTEXTYPE_LEFTBOTTOM).setValue(x,y);
x =Element.getDoubleValue(element.getChild(AbstractRectangle.XML_RIGHTBOTTOMX));
y =Element.getDoubleValue(element.getChild(AbstractRectangle.XML_RIGHTBOTTOMY));
m_rect.getVertex(Rect.VERTEXTYPE_RIGHTBOTTOM).setValue(x,y);
initNodes();
m_objList.fromDOM(element.getChild(m_objList.getXMLTag()),version);
}
/**
* 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);
//append m_rect to stream
JFPoint pnt;
pnt =m_rect.getVertex(Rect.VERTEXTYPE_LEFTTOP);
stream.writeDouble(pnt.getX());
stream.writeDouble(pnt.getY());
pnt =m_rect.getVertex(Rect.VERTEXTYPE_RIGHTTOP);
stream.writeDouble(pnt.getX());
stream.writeDouble(pnt.getY());
pnt =m_rect.getVertex(Rect.VERTEXTYPE_LEFTBOTTOM);
stream.writeDouble(pnt.getX());
stream.writeDouble(pnt.getY());
pnt =m_rect.getVertex(Rect.VERTEXTYPE_RIGHTBOTTOM);
stream.writeDouble(pnt.getX());
stream.writeDouble(pnt.getY());
m_objList.saveToStream(stream,version);
}
/**
* 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);
double x=0,y=0;
x =stream.readDouble();
y =stream.readDouble();
m_rect.getVertex(Rect.VERTEXTYPE_LEFTTOP).setValue(x,y);
x =stream.readDouble();
y =stream.readDouble();
m_rect.getVertex(Rect.VERTEXTYPE_RIGHTTOP).setValue(x,y);
x =stream.readDouble();
y =stream.readDouble();
m_rect.getVertex(Rect.VERTEXTYPE_LEFTBOTTOM).setValue(x,y);
x =stream.readDouble();
y =stream.readDouble();
m_rect.getVertex(Rect.VERTEXTYPE_RIGHTBOTTOM).setValue(x,y);
initNodes();
m_objList.loadFromStream(stream,false,version);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -