📄 wfline.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
* Portions created by Jorg Janke are Copyright (C) 1999-2002 Jorg Janke, parts
* created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.apps.wf;
import java.awt.*;
import javax.swing.*;
import org.compiere.model.*;
/**
* Work Flow Line between Nodes
*
* @author Jorg Janke
* @version $Id: WFLine.java,v 1.3 2002/12/05 05:42:03 jjanke Exp $
*/
public class WFLine extends JComponent
{
/**
* Create Line
* @param next model
*/
public WFLine (MWFNodeNext next)
{
m_next = next;
setOpaque(true);
} // WFLine
/** Model */
private MWFNodeNext m_next = null;
/** From Node */
private Rectangle m_from = null;
/** To Node */
private Rectangle m_to = null;
/**
* Get From
* @return from node
*/
public Rectangle getFrom()
{
return m_from;
} // getFrom
/**
* Set From
* @param from from node
*/
public void setFrom(Rectangle from)
{
m_from = from;
} // setFrom
/**
* Get To
* @return to node
*/
public Rectangle getTo()
{
return m_to;
} // getTo
/**
* Set To
* @param to to node
*/
public void setTo(Rectangle to)
{
m_to = to;
} // setTo
/**
* Get From Node ID
* @return from node id
*/
public int getAD_WF_Node_ID()
{
return m_next.getAD_WF_Node_ID();
} // getAD_WF_Node_ID
/**
* Get To Node ID
* @return to node id
*/
public int getAD_WF_Next_ID()
{
return m_next.getAD_WF_Next_ID();
} // getAD_WF_Next_ID
/*************************************************************************/
/**
* Paint it
* @param g Graph
*/
protected void paintComponent (Graphics g)
{
if (m_from == null || m_to == null)
return;
Polygon arrow = new Polygon();
// left \ down
if (m_from.x+m_from.width <= m_to.x
&& m_from.y+m_from.height <= m_to.y)
{
addPoint (arrow, m_from, SwingConstants.RIGHT, true);
addPoint (arrow, m_to, SwingConstants.TOP, false);
}
// top | down
else if (m_from.y+m_from.height <= m_to.y)
{
addPoint (arrow, m_from, SwingConstants.BOTTOM, true);
addPoint (arrow, m_to, SwingConstants.TOP, false);
}
// bottom / up
else if (m_to.y+m_to.height <= m_from.y)
{
addPoint (arrow, m_from, SwingConstants.TOP, true);
addPoint (arrow, m_to, SwingConstants.BOTTOM, false);
}
// right o <- o left
else if (m_to.x+m_to.width <= m_from.x)
{
addPoint (arrow, m_from, SwingConstants.LEFT, true);
addPoint (arrow, m_to, SwingConstants.RIGHT, false);
}
// left o -> o right
else // if (isL_R())
{
addPoint (arrow, m_from, SwingConstants.RIGHT, true);
addPoint (arrow, m_to, SwingConstants.LEFT, false);
}
// Paint it
g.setColor(Color.cyan);
g.fillPolygon(arrow);
g.setColor(Color.blue);
g.drawPolygon(arrow);
} // paintComponent
/**
* Get Point of Rectangle
* @param arrow Polygon to draw arrow
* @param rect Rectangle
* @param pos SwingConstants.BOTTOM / TOP / RIGHT / LEFT
* @param from if true from (base) else to (tip) of arrow
*/
private void addPoint (Polygon arrow, Rectangle rect, int pos, boolean from)
{
int x = rect.x;
int y = rect.y;
if (pos == SwingConstants.TOP)
{
x += rect.width/2;
if (from)
{
arrow.addPoint(x-2, y);
arrow.addPoint(x+2, y);
}
else
arrow.addPoint(x, y);
}
else if (pos == SwingConstants.RIGHT)
{
x += rect.width;
y += rect.height/2;
if (from)
{
arrow.addPoint(x, y-2);
arrow.addPoint(x, y+2);
}
else
arrow.addPoint(x, y);
}
else if (pos == SwingConstants.LEFT)
{
y += rect.height/2;
if (from)
{
arrow.addPoint(x, y-2);
arrow.addPoint(x, y+2);
}
else
arrow.addPoint(x, y);
}
else // if (pos == SwingConstants.BOTTOM)
{
x += rect.width/2;
y += rect.height;
if (from)
{
arrow.addPoint(x-2, y);
arrow.addPoint(x+2, y);
}
else
arrow.addPoint(x, y);
}
} // getPoint
/**
* Get Preferred Size
* @return size
*/
public Dimension getPreferredSize()
{
if (m_from == null || m_to == null)
return super.getPreferredSize();
//
int width = Math.max(m_from.x + m_from.width, m_to.x + m_to.width);
int height = Math.max(m_from.y + m_from.height, m_to.y + m_to.height);
//
return new Dimension(width, height);
} // getPreferredSize
/**
* String Representation
* @return info
*/
public String toString()
{
StringBuffer sb = new StringBuffer("WFLine[");
sb.append(getAD_WF_Node_ID()).append("->").append(getAD_WF_Next_ID());
sb.append("]");
return sb.toString();
} // toString
} // WFLine
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -