📄 abstractshape.java
字号:
*/
public Node getNodeByIndex(int index){
AbstractObject obj =m_nodeList.getByIndex(index);
if (obj==null)
return null;
else
return (Node)obj;
}
/**
* Get a specified node by object id
*
* @param objectId Object id for specified node.
*
* @return The node object.
*
*/
public Node getNodeByObjectId(int objectId){
AbstractObject obj =m_nodeList.getByObjectId(objectId);
if (obj==null)
return null;
else
return (Node)obj;
}
/**
* Add a new node for current node list.
*
* @param pnt A new point for node.
*
*/
public void addNode(JFPoint pnt){
addNode(pnt.getX(),pnt.getY());
}
/**
* Add a new node for current node list.
*
* @param x, y Coordinates of a new node.
*
*/
public void addNode(double x, double y){
try{
m_nodeList.add(new Node(x,y));
}catch(Exception e){
}
}
/**
* Ask if this object is rotatable.
*
* @return true if rotatable, false otherwise.
*
*/
public boolean isRotatable(){
return true;
}
/**
* Ask if this object is an open shape,e.g. line,curve,arc,etc.
*
* @return true if open,false closed.
*
*/
public boolean isOpenShape(){
return false;
}
/**
* Rotate an object by moving a node of current object.
*
* @param nodePoint Currently moving node's point position. This will be actually an object's node,
* but also can be an fictitious node of multi objects(in multi rotation actions)
*
* @param rotateCenter A rotate center specified, if null use center point instead.
* @param x, y Moving offsets.
*
* @param g A graphic canvas.
*
*/
public void rotateNode(JFPoint nodePoint, JFPoint rotateCenter,double x, double y,Graphics g){
if (nodePoint==null) return;
JFPoint center =rotateCenter;
if (center==null){
Rect rect =getBounds();
center =rect.getCenter();
if (center==null) return;
}
double lastX =nodePoint.getX();
double lastY =nodePoint.getY();
double theta =Angle.getAngle(center.getX(),center.getY(),lastX,lastY,x,y,true);
if ((float)theta==0){
return;
}else{
rotateBy(center.getX(),center.getY(),theta);
}
}
/**
* When moving a node, in some cases, e.g. ctrl key or shift key pressed to force preserving
* the form of a shape, or force equilateral shapes, we need to recalculate the actual moving
* node's position.
*
* @param movePos Desire moving position of a node.
* @param moveCase Move case of a node, normal, shift key pressed or ctrl key pressed
* @return The actual moving position of a node.
*
*/
public JFPoint getMoveNodePos(Node node,JFPoint movePos,int moveCase){
return movePos;
}
/**
* Start move a node.
*
* @param node The node will be moved.
*
*/
public void startMoveNode(Node node){
}
/**
* Move/adjust a node of current object.
*
* @param node Currently moving node.
*
* @param x, y Moving offsets.
*
* @param g current drawing canvas.
*
*/
public void moveNode(Node node, double x, double y,Graphics g){
}
/**
* finish move/adjust a node of current object.
*
* @param node Currently moving node.
*
* @param x, y Moving offsets.
*
* @param g current drawing canvas.
*
*/
public void finishMoveNode(Node node, double x, double y,Graphics g){
}
/**
* If an object has already necessary points so can be constructed.
* @return True when complete, false otherwise.
*
*/
public boolean ifCompleteDrawing(){
return true;
}
/**
* Finish drawing object.
*
*/
public boolean finishDrawing(){
return true;
}
/**
* Add a new port to this shape.
* @param x,y Current picking position.
*
*/
public Port addPort(double x,double y){
return null;
}
/**
* Pick a port that is on the shape, according to the current x,y position
* @param x,y Current picking position.
*
*/
public Port pickPort(double x,double y){
return m_portList.pickPort(x,y);
}
/**
* Remove a port from this shape.
* @param port A port to be removed.
*
*/
public boolean removePort(Port port){
return m_portList.removePort(port);
}
/**
* Attach current shape to a specified port of other shape.
* @param port A new port of other shape.
*
*/
public boolean attachPort(Port port){
return m_portList.attachPort(port);
}
/**
* Detach current shape to a specified port of other shape.
* @param port A port of other shape.
*
*/
public boolean detachPort(Port port){
return m_portList.detachPort(port);
}
/**
* fetch all sub objects of this objects,then add them into objList.
*/
public void fetchSubObjects(ObjectList objList){
//do nothing here but subclasses.e.g. JFGroup.
}
/**
* 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.
*/
public void attachRealPort(){
ObjectList list =new ObjectList();
list.add(this);
fetchSubObjects(list);
attachRealPort(list);
}
/**
* 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(ObjectList shapeList){
m_portList.attachRealPort(shapeList);
}
/**
* Remove last node added by addNode method.
* @return Last node that remained.
*
*/
public Node removeLastNode(){
return m_nodeList.removeLastNode();
}
/**
* Get a number of all the ports of a AbstractShape
* a port is a point which is on AbstractShape and used to connect other AbstractShapes
*
* @return The number of ports.
*
*/
public int getPortCount(){
return m_portList.size();
}
/**
* Get a port list of this shape. A shape should always has a port list.
*
* @return The port list.
*
*/
public ObjectList getPortList(){
return m_portList;
}
/**
* Set a port list of this shape.
*
* @param portList A new port list.
* @param shapeList All shape objects in a list.
*
*/
public void setPortList(ObjectList portList,ObjectList shapeList){
//this feature will be overrode by sub classes
//here it will do nothing.
}
/**
* Get a specified port by index
*
* @param index An index of port
*
* @return The port object.
*
*/
public Port getPortByIndex(int index){
AbstractObject obj = m_portList.getByIndex(index);
if (obj==null)
return null;
else
return (Port)obj;
}
/**
* Get a specified port by object id
*
* @param objectId Object id for specified port.
*
* @return The port object.
*
*/
public Port getPortByObjectId(int objectId){
AbstractObject obj = m_portList.getByObjectId(objectId);
if (obj==null)
return null;
else
return (Port)obj;
}
/**
* Get a number of all the properties of a AbstractShape
*
* @return The number of properties.
*
*/
public int getPropertyCount(){
return m_propertyList.size();
}
/**
* Get a property list of this shape. A shape should always has a property list.
*
* @return The property list.
*
*/
public ObjectList getPropertyList(){
return m_propertyList;
}
/**
* Get a specified property by index
*
* @param index An index of property
*
* @return The property object.
*
*/
public Property getPropertyByIndex(int index){
AbstractObject obj = m_propertyList.getByIndex(index);
if (obj==null)
return null;
else
return (Property)obj;
}
/**
* Get a specified property by object id
*
* @param objectId Object id for specified property.
*
* @return The property object.
*
*/
public Property getPropertyByObjectId(int objectId){
AbstractObject obj = m_propertyList.getByObjectId(objectId);
if (obj==null)
return null;
else
return (Property)obj;
}
/**
* Get the bounds of this shape.
*
* @return The bounds rectangle of current shape.
*
*/
public Rect getBounds(){
return m_nodeList.getBounds();
}
/**
* Draw label of current shape.
*
* @param g A graphic canvas.
*
*/
public void drawLabel(Graphics g){
Graphics2D g2 =(Graphics2D)g;
g2.setColor(m_fontFormat.getFontColor());
Composite originalComposite =g2.getComposite();
int transparency =m_fontFormat.getTransparency();
if (transparency>0){
g2.setComposite(getTransparencyComposite(transparency));
}
if (m_fontFormat.isUseStrokeAndFill()){
String s =m_label.getText();
JFPoint pnt =m_label.getDrawPoint(g,true);
int x =(int)pnt.getX();
int y =(int)pnt.getY();
TextRender.drawStrokeAndFillText(g,s,x,y,m_fontFormat,getZoomScale());
}else
m_label.draw(g);
if (transparency>0){
g2.setComposite(originalComposite);
}
}
/**
* Draw a label picked state of current shape.
*
* @param g A graphic canvas.
*
*/
public void drawLabelPicked(Graphics g){
m_label.drawPicked(g,false);
}
/**
* Draw ports of current shape.
*
* @param g A graphic canvas.
*
*/
public void drawPort(Graphics g){
if (isShowDesign())
m_portList.draw(g);
}
/**
* Draw picked state of current object on graphic canvas.
*
* @param g A graphic canvas.
* @param ifRotate If user's operation or other actions force objects to be rotated.
*
*/
public void drawPicked(Graphics g, boolean ifRotate){
double zoom =getZoomScale();
((Graphics2D)g).setStroke(new BasicStroke(1));
//if this shape is invisible, so draw virtual nodes
if (isInvisible()){
initBoundsNodeList();
m_boundsNodeList.draw(g,false);
//shape is visible, so draw each actual node
}else{
m_nodeList.draw(g,ifRotate);
drawPort(g);
if (!ifRotate)
drawLabelPicked(g);
}
}
/**
* Init bounds node list method is to get the four nodes
* of the bounds, then rebuild the bounds node list.
*
*/
protected void initBoundsNodeList(){
try{
while (m_boundsNodeList.size()<4){
m_boundsNodeList.add(new Node());
}
Node node1 =(Node)m_boundsNodeList.getList().get(0);
Node node2 =(Node)m_boundsNodeList.getList().get(1);
Node node3 =(Node)m_boundsNodeList.getList().get(2);
Node node4 =(Node)m_boundsNodeList.getList().get(3);
Rect rect =getBounds();
node1.setNodePoint(rect.getVertex(Rect.VERTEXTYPE_LEFTTOP));
node1.setParent(this);
node2.setNodePoint(rect.getVertex(Rect.VERTEXTYPE_RIGHTTOP));
node2.setParent(this);
node3.setNodePoint(rect.getVertex(Rect.VERTEXTYPE_LEFTBOTTOM));
node3.setParent(this);
node4.setNodePoint(rect.getVertex(Rect.VERTEXTYPE_RIGHTBOTTOM));
node4.setParent(this);
m_boundsNodeList.setZoomScale(getZoomScale());
}catch(Exception e){
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -