📄 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 Smart Business Solution. The Initial
* Developer of the Original Code is Jorg Janke. Portions created by Jorg Janke
* are Copyright (C) 1999-2005 Jorg Janke.
* All parts are Copyright (C) 1999-2005 ComPiere, Inc. All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.apps.wf;
import java.awt.*;
import org.compiere.util.*;
/**
* WorkFlow Layout Manager
*
* @author Jorg Janke
* @version $Id: WFLayoutManager.java,v 1.11 2005/10/11 02:28:11 jjanke Exp $
*/
public class WFLayoutManager implements LayoutManager
{
/**
* Constructor
*/
public WFLayoutManager()
{
} // WFLayoutManager
/** Logger */
private static CLogger log = CLogger.getCLogger(WFLayoutManager.class);
/** 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
* @see java.awt.LayoutManager#addLayoutComponent(String, Component)
*/
public void addLayoutComponent (String name, Component comp)
{
invalidateLayout();
} // addLayoutComponent
/**
* Removes the specified component from the layout.
* @param comp the component to be removed
* @see java.awt.LayoutManager#removeLayoutComponent(Component)
*/
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
* @see java.awt.LayoutManager#layoutContainer(Container)
*/
public void layoutContainer (Container parent)
{
Insets insets = parent.getInsets();
//
int width = insets.left;
int height = insets.top;
// We need to layout
if (needLayout(parent))
{
int x = 5;
int y = 5;
// 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();
comp.setLocation(x, y);
comp.setBounds(x, y, ps.width, ps.height);
//
width = x + ps.width;
height = y + ps.height;
// next pos
if (x == 5)
x = 230;
else
{
x = 5;
y += 100;
}
// x += ps.width-20;
// y += ps.height+20;
}
}
}
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
WFContentPanel panel = (WFContentPanel)parent;
panel.createLines();
// Calculate size
width += insets.right;
height += insets.bottom;
// return size
m_size = new Dimension(width, height);
log.finer("Size=" + m_size);
} // layoutContainer
/**
* Need Layout
* @param parent parent
* @return true if we need to layout
*/
private boolean needLayout (Container parent)
{
Point p00 = 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(p00))
{
log.fine(comp.toString());
return true;
}
}
return false;
} // needLayout
/**
* 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 + -