1 14 package org.compiere.apps.wf; 15 16 import java.awt.*; 17 import java.util.*; 18 import javax.swing.*; 19 20 import org.compiere.util.*; 21 22 28 public class WFLayoutManager implements LayoutManager 29 { 30 31 34 public WFLayoutManager() 35 { 36 } 38 39 private Dimension m_size = null; 40 41 50 public void addLayoutComponent (String name, Component comp) 51 { 52 invalidateLayout(); 53 } 55 59 public void removeLayoutComponent(Component comp) 60 { 61 if (comp == null) 62 return; 63 invalidateLayout(); 64 } 66 73 public Dimension preferredLayoutSize(Container parent) 74 { 75 if (m_size == null) 76 layoutContainer(parent); 77 return m_size; 78 } 80 87 public Dimension minimumLayoutSize(Container parent) 88 { 89 return preferredLayoutSize(parent); 90 } 92 96 public void layoutContainer (Container parent) 97 { 98 Insets insets = parent.getInsets(); 99 int width = insets.left; 101 int height = insets.top; 102 103 105 if (needLayout(parent)) 107 { 108 for (int i = 0; i < parent.getComponentCount(); i++) 110 { 111 Component comp = parent.getComponent(i); 112 if (comp.isVisible() && comp instanceof WFNode) 113 { 114 Dimension ps = comp.getPreferredSize(); 115 int x = width; 116 int y = height; 117 comp.setBounds(x, y, ps.width, ps.height); 118 width += ps.getWidth(); 120 height += ps.getHeight(); 121 } 122 } 123 } 124 else { 126 for (int i = 0; i < parent.getComponentCount(); i++) 128 { 129 Component comp = parent.getComponent(i); 130 if (comp.isVisible() && comp instanceof WFNode) 131 { 132 Dimension ps = comp.getPreferredSize(); 133 Point loc = comp.getLocation(); 134 int maxWidth = comp.getX() + ps.width; 135 int maxHeight = comp.getY() + ps.height; 136 if (width < maxWidth) 137 width = maxWidth; 138 if (height < maxHeight) 139 height = maxHeight; 140 comp.setBounds(loc.x, loc.y, ps.width, ps.height); 141 } 142 } } 145 for (int i = 0; i < parent.getComponentCount(); i++) 147 { 148 Component comp = parent.getComponent(i); 149 if (comp.isVisible() && comp instanceof WFLine) 150 { 151 WFLine line = (WFLine)comp; 152 Rectangle from = findBounds (parent, line.getAD_WF_Node_ID()); 153 Rectangle to = findBounds (parent, line.getAD_WF_Next_ID()); 154 line.setFrom(from); 155 line.setTo(to); 156 Dimension ps = line.getPreferredSize(); 157 line.setBounds(0, 0, ps.width, ps.height); 158 } 159 } 161 width += insets.right; 163 height += insets.bottom; 164 m_size = new Dimension(width, height); 165 } 167 172 private boolean needLayout (Container parent) 173 { 174 Point p0 = new Point(0,0); 175 for (int i = 0; i < parent.getComponentCount(); i++) 177 { 178 Component comp = parent.getComponent(i); 179 if (comp instanceof WFNode && comp.getLocation().equals(p0)) 180 { 181 Log.trace(Log.l6_Database, "WFLayout.needLayout", comp); 182 return true; 183 } 184 } 185 return false; 186 } 188 194 private Rectangle findBounds (Container parent, int AD_WF_Node_ID) 195 { 196 for (int i = 0; i < parent.getComponentCount(); i++) 197 { 198 Component comp = parent.getComponent(i); 199 if (comp instanceof WFNode) 200 { 201 WFNode node = (WFNode)comp; 202 if (node.getAD_WF_Node_ID() == AD_WF_Node_ID) 203 return node.getIconBounds(); 204 } 205 } 206 return null; 207 } 209 213 private void invalidateLayout() 214 { 215 m_size = null; 216 } 218 } | Popular Tags |