📄 wflayoutmanager.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 java.util.*;
import javax.swing.*;
import org.compiere.util.*;
/**
* WorkFlow Layout Manager
*
* @author Jorg Janke
* @version $Id: WFLayoutManager.java,v 1.3 2002/12/05 05:29:30 jjanke Exp $
*/
public class WFLayoutManager implements LayoutManager
{
/**
* Constructor
*/
public WFLayoutManager()
{
} // WFLayoutManager
/** Cached Size */
private Dimension m_size = null;
/**
* If the layout manager uses a per-component string,
* adds the component <code>comp</code> to the layout,
* associating it
* with the string specified by <code>name</code>.
*
* @param name the string to be associated with the component
* @param comp the component to be added
*/
public void addLayoutComponent (String name, Component comp)
{
invalidateLayout();
} // addLayoutComponent
/**
* Removes the specified component from the layout.
* @param comp the component to be removed
*/
public void removeLayoutComponent(Component comp)
{
if (comp == null)
return;
invalidateLayout();
} // removeLayoutComponent
/**
* Calculates the preferred size dimensions for the specified
* container, given the components it contains.
* @param parent the container to be laid out
* @return preferred size
* @see #minimumLayoutSize
*/
public Dimension preferredLayoutSize(Container parent)
{
if (m_size == null)
layoutContainer(parent);
return m_size;
} // preferredLayoutSize
/**
* Calculates the minimum size dimensions for the specified
* container, given the components it contains.
* @param parent the component to be laid out
* @return preferred size
* @see #preferredLayoutSize
*/
public Dimension minimumLayoutSize(Container parent)
{
return preferredLayoutSize(parent);
} // minimumLayoutSize
/**
* Lays out the specified container.
* @param parent the container to be laid out
*/
public void layoutContainer (Container parent)
{
Insets insets = parent.getInsets();
//
int width = insets.left;
int height = insets.top;
// WFPanel panel = (WFPanel)parent;
// We need to layout
if (needLayout(parent))
{
// Go through all components
for (int i = 0; i < parent.getComponentCount(); i++)
{
Component comp = parent.getComponent(i);
if (comp.isVisible() && comp instanceof WFNode)
{
Dimension ps = comp.getPreferredSize();
int x = width;
int y = height;
comp.setBounds(x, y, ps.width, ps.height);
//
width += ps.getWidth();
height += ps.getHeight();
}
}
}
else // we have an Layout
{
// Go through all components
for (int i = 0; i < parent.getComponentCount(); i++)
{
Component comp = parent.getComponent(i);
if (comp.isVisible() && comp instanceof WFNode)
{
Dimension ps = comp.getPreferredSize();
Point loc = comp.getLocation();
int maxWidth = comp.getX() + ps.width;
int maxHeight = comp.getY() + ps.height;
if (width < maxWidth)
width = maxWidth;
if (height < maxHeight)
height = maxHeight;
comp.setBounds(loc.x, loc.y, ps.width, ps.height);
}
} // for all components
} // have layout
// Create Lines
for (int i = 0; i < parent.getComponentCount(); i++)
{
Component comp = parent.getComponent(i);
if (comp.isVisible() && comp instanceof WFLine)
{
WFLine line = (WFLine)comp;
Rectangle from = findBounds (parent, line.getAD_WF_Node_ID());
Rectangle to = findBounds (parent, line.getAD_WF_Next_ID());
line.setFrom(from);
line.setTo(to);
Dimension ps = line.getPreferredSize();
line.setBounds(0, 0, ps.width, ps.height);
}
} // for all components
// return size
width += insets.right;
height += insets.bottom;
m_size = new Dimension(width, height);
} // layoutContainer
/**
* Need Layout
* @param parent parent
* @return true if we need to layout
*/
private boolean needLayout (Container parent)
{
Point p0 = new Point(0,0);
// Go through all components
for (int i = 0; i < parent.getComponentCount(); i++)
{
Component comp = parent.getComponent(i);
if (comp instanceof WFNode && comp.getLocation().equals(p0))
{
Log.trace(Log.l6_Database, "WFLayout.needLayout", comp);
return true;
}
}
return false;
} // needLayout
/**
* Get Bounds of WF Node Icon
* @param parent parent (WFPanel)
* @param AD_WF_Node_ID node id
* @return bounds of node with ID or null
*/
private Rectangle findBounds (Container parent, int AD_WF_Node_ID)
{
for (int i = 0; i < parent.getComponentCount(); i++)
{
Component comp = parent.getComponent(i);
if (comp instanceof WFNode)
{
WFNode node = (WFNode)comp;
if (node.getAD_WF_Node_ID() == AD_WF_Node_ID)
return node.getIconBounds();
}
}
return null;
} // findBounds
/**
* Invalidates the layout, indicating that if the layout manager
* has cached information it should be discarded.
*/
private void invalidateLayout()
{
m_size = null;
} // invalidateLayout
} // WFLayoutManager
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -