📄 selection.java
字号:
Port port =((AbstractShape)obj).pickPort(x,y);
if (port!=null)
return port;
}
}
return null;
}
/**
* Remove a port from this selection.
* @param port A port to be removed.
*
*/
public boolean removePort(Port port){
AbstractObject obj;
Iterator it=m_objectList.getList().iterator();
while (it!=null && it.hasNext()){
obj =(AbstractObject)it.next();
if (obj!=null && obj instanceof AbstractShape){
if (((AbstractShape)obj).removePort(port))
return true;
}
}
return false;
}
/**
* Get all the arrow format of objects in this selection.
*
* @return The arrow format.
*
*/
public Arrow getArrow(){
AbstractShape obj;
Iterator it=m_objectList.getList().iterator();
while (it!=null && it.hasNext()){
obj =(AbstractShape)it.next();
Arrow arrow =obj.getArrow();
if (arrow!=null)
return arrow;
}
return null;
}
/**
* Set all the arrow format of object in this selection.
*
* @param arrow A new arrow format object.
*
*/
public void setArrow(Arrow arrow){
if (arrow==null)
return;
AbstractShape obj;
Iterator it=m_objectList.getList().iterator();
while (it!=null && it.hasNext()){
obj =(AbstractShape)it.next();
obj.setArrow(arrow);
}
}
/**
* Get all the line format of objects in this selection.
*
* @return The line format.
*
*/
public LineFormat getLineFormat(){
AbstractShape obj;
Iterator it=m_objectList.getList().iterator();
while (it!=null && it.hasNext()){
obj =(AbstractShape)it.next();
LineFormat lineFormat =obj.getLineFormat();
if (lineFormat!=null)
return lineFormat;
}
return null;
}
/**
* Set the line format of objects in this selection.
*
* @param lineFormat A new line format.
*
*/
public void setLineFormat(LineFormat lineFormat){
if (lineFormat==null)
return;
AbstractShape obj;
Iterator it=m_objectList.getList().iterator();
while (it!=null && it.hasNext()){
obj =(AbstractShape)it.next();
obj.setLineFormat(lineFormat);
}
}
/**
* Get all the fill format of objects in this selection.
*
* @return The fill format.
*
*/
public FillFormat getFillFormat(){
AbstractShape obj;
Iterator it=m_objectList.getList().iterator();
while (it!=null && it.hasNext()){
obj =(AbstractShape)it.next();
FillFormat fillFormat =obj.getFillFormat();
if (fillFormat!=null)
return fillFormat;
}
return null;
}
/**
* Set the fill format of objects in this selection.
*
* @param fillFormat A new fill format.
*
*/
public void setFillFormat(FillFormat fillFormat){
if (fillFormat==null)
return;
AbstractShape obj;
Iterator it=m_objectList.getList().iterator();
while (it!=null && it.hasNext()){
obj =(AbstractShape)it.next();
obj.setFillFormat(fillFormat);
}
}
/**
* Get all the font format of objects in this selection.
*
* @return The font format.
*
*/
public FontFormat getFontFormat(){
AbstractShape obj;
Iterator it=m_objectList.getList().iterator();
while (it!=null && it.hasNext()){
obj =(AbstractShape)it.next();
FontFormat fontFormat =obj.getFontFormat();
if (fontFormat!=null)
return fontFormat;
}
return null;
}
/**
* Set the font format of objects in this selection.
*
* @param fontFormat A new font format.
*
*/
public void setFontFormat(FontFormat fontFormat){
if (fontFormat==null)
return;
AbstractShape obj;
Iterator it=m_objectList.getList().iterator();
while (it!=null && it.hasNext()){
obj =(AbstractShape)it.next();
obj.setFontFormat(fontFormat);
}
}
/**
* Flip objects of current selection. We make a up-down flip here.
* @return the flip baseY coordinate.
*/
public double flipObjects(){
Rect rect =getBounds();
double baseX =rect.getX() + rect.getWidth()/2;
double baseY =rect.getY() + rect.getHeight()/2;
Iterator it =m_objectList.getList().iterator();
while (it!=null && it.hasNext()){
Object obj =it.next();
if (obj!=null && obj instanceof AbstractShape){
AbstractShape shape =(AbstractShape)obj;
if (!shape.isDisableMotion()){
shape.flipBy(baseY);
}
}
}
return baseY;
}
/**
* Mirror objects of current selection. We make a left-right mirror here.
* @return the mirror baseX coordinate.
*/
public double mirrorObjects(){
Rect rect =getBounds();
double baseX =rect.getX() + rect.getWidth()/2;
double baseY =rect.getY() + rect.getHeight()/2;
Iterator it =m_objectList.getList().iterator();
while (it!=null && it.hasNext()){
Object obj =it.next();
if (obj!=null && obj instanceof AbstractShape){
AbstractShape shape =(AbstractShape)obj;
if (!shape.isDisableMotion()){
shape.mirrorBy(baseX);
}
}
}
return baseX;
}
/**
* Move current selection by a new offset.
*
* @param x, y A new moving offset.
*/
public void moveBy(double x, double y){
AbstractObject obj;
Iterator it=m_objectList.getList().iterator();
while (it!=null && it.hasNext()){
obj =(AbstractObject)it.next();
if (obj!=null && obj instanceof AbstractShape){
AbstractShape shape =(AbstractShape)obj;
if (!shape.isDisableMotion()){
shape.moveBy(x,y);
}
}
}
}
/**
* Get a move offset(x,y) from source position to destination position.
*
* @param oldx,oldy Source position of this selection.
* @param newx,newy Destination position of this selection.
*
* @return The move offset point.
*
*/
public JFPoint getMovePos(double oldx, double oldy, double newx, double newy){
GridFormat gridFormat =m_drawCanvas.getGridFormat();
double xOffset =newx-oldx;
double yOffset =newy-oldy;
if (!gridFormat.getSnapToGrid()){
return new JFPoint(xOffset,yOffset);
}else{
Rect bounds =getBounds();
double x =bounds.getX()+xOffset;
double y =bounds.getY()+yOffset;
JFPoint snapPos =gridFormat.getSnapPos(x,y);
return new JFPoint(snapPos.getX()-bounds.getX(),snapPos.getY()-bounds.getY());
}
}
/**
* Move current selection at a new position
*
* @param x, y A new position.
* @param g Graphics context to draw selections.
*
*/
public void moveTo(double x, double y,Graphics g){
Graphics2D g2 =(Graphics2D)g;
g2.setXORMode(Color.white);
//if moved already, then re-draw it to eliminate the xor shape.
if (!m_lastPoint.equals(m_originalPoint,true)){
draw(g,true);
}
JFPoint movePos =getMovePos(m_lastPoint.getX(),m_lastPoint.getY(),x,y);
//draw a new xor shape of selection(but avoided to draw on original position).
moveBy(movePos.getX(),movePos.getY());
//avoid drawing on the original position.
if (!m_originalPoint.equals(x,y,true)){
draw(g,true);
}
//save the new position.
m_lastPoint.setX(x);
m_lastPoint.setY(y);
}
/**
* get first object in selection.
*/
public AbstractShape getFirstObj(){
AbstractObject obj=null;
try{
obj = m_objectList.getByIndex(0);
if (obj==null || !(obj instanceof AbstractShape))
return null;
}catch(Exception e){
return null;
}
return (AbstractShape)obj;
}
/**
* get current dragging object.
*/
private AbstractShape getDraggingObj(){
//get the current shape,only one shape in selection while in node dragging state.
return getFirstObj();
}
/**
* Get internal label of one shape in the selection that intersects with point pnt.
*
* @param pnt A JFPoint used to test intersection.
* @param g A graphics text used necessary in label intersection operation.
* @return Internal label of current shape.
*
*/
public Label labelIntersects(Graphics g,JFPoint pnt){
AbstractObject obj;
Iterator it=m_objectList.getList().iterator();
while (it!=null && it.hasNext()){
obj =(AbstractObject)it.next();
if (obj!=null && obj instanceof AbstractShape){
Label label =((AbstractShape)obj).labelIntersects(g,pnt);
if (label!=null)
return label;
}
}
return null;
}
/**
* Drag current label.
*
* @param lastx, lasty Last mouse position.
* @param newx, newy New mouse position.
*
* @param g Graphics context to draw selections.
*
*/
public void dragLabel(double lastx, double lasty, double newx, double newy,Graphics g){
Label moveLabel=getMoveLabel();
if (moveLabel==null)
return;
Graphics2D g2 =(Graphics2D)g;
g2.setXORMode(Color.white);
if ((int)lastx!=(int)newx || (int)lasty!=(int)newy)
moveLabel.drawPicked(g,true);
moveLabel.moveBy(newx-lastx,newy-lasty);
if ((int)lastx!=(int)newx || (int)lasty!=(int)newy)
moveLabel.drawPicked(g,true);
}
/**
* Get which node of one shape in the selection that intersects with point pnt.
*
* @param pnt A JFPoint used to test intersection.
* @param usage Purpose to get a node intersected, e.g. move or rotate.
*
* @return A node of current shape.
*
*/
public Node nodeIntersects(JFPoint pnt,int usage){
AbstractObject obj;
Iterator it=m_objectList.getList().iterator();
while (it!=null && it.hasNext()){
obj =(AbstractObject)it.next();
if (obj!=null && obj instanceof AbstractShape){
Node node =((AbstractShape)obj).nodeIntersects(pnt,usage);
if (node!=null)
return node;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -