1 14 package org.compiere.apps.wf; 15 16 import java.awt.*; 17 import javax.swing.*; 18 19 import org.compiere.model.*; 20 21 22 28 public class WFLine extends JComponent 29 { 30 34 public WFLine (MWFNodeNext next) 35 { 36 m_next = next; 37 setOpaque(true); 38 } 40 41 private MWFNodeNext m_next = null; 42 43 44 private Rectangle m_from = null; 45 46 private Rectangle m_to = null; 47 48 52 public Rectangle getFrom() 53 { 54 return m_from; 55 } 57 61 public void setFrom(Rectangle from) 62 { 63 m_from = from; 64 } 66 70 public Rectangle getTo() 71 { 72 return m_to; 73 } 75 79 public void setTo(Rectangle to) 80 { 81 m_to = to; 82 } 84 88 public int getAD_WF_Node_ID() 89 { 90 return m_next.getAD_WF_Node_ID(); 91 } 93 97 public int getAD_WF_Next_ID() 98 { 99 return m_next.getAD_WF_Next_ID(); 100 } 102 103 104 108 protected void paintComponent (Graphics g) 109 { 110 if (m_from == null || m_to == null) 111 return; 112 113 Polygon arrow = new Polygon(); 114 if (m_from.x+m_from.width <= m_to.x 116 && m_from.y+m_from.height <= m_to.y) 117 { 118 addPoint (arrow, m_from, SwingConstants.RIGHT, true); 119 addPoint (arrow, m_to, SwingConstants.TOP, false); 120 } 121 else if (m_from.y+m_from.height <= m_to.y) 123 { 124 addPoint (arrow, m_from, SwingConstants.BOTTOM, true); 125 addPoint (arrow, m_to, SwingConstants.TOP, false); 126 } 127 else if (m_to.y+m_to.height <= m_from.y) 129 { 130 addPoint (arrow, m_from, SwingConstants.TOP, true); 131 addPoint (arrow, m_to, SwingConstants.BOTTOM, false); 132 } 133 else if (m_to.x+m_to.width <= m_from.x) 135 { 136 addPoint (arrow, m_from, SwingConstants.LEFT, true); 137 addPoint (arrow, m_to, SwingConstants.RIGHT, false); 138 } 139 else { 142 addPoint (arrow, m_from, SwingConstants.RIGHT, true); 143 addPoint (arrow, m_to, SwingConstants.LEFT, false); 144 } 145 146 g.setColor(Color.cyan); 148 g.fillPolygon(arrow); 149 g.setColor(Color.blue); 150 g.drawPolygon(arrow); 151 } 153 154 161 private void addPoint (Polygon arrow, Rectangle rect, int pos, boolean from) 162 { 163 int x = rect.x; 164 int y = rect.y; 165 166 if (pos == SwingConstants.TOP) 167 { 168 x += rect.width/2; 169 if (from) 170 { 171 arrow.addPoint(x-2, y); 172 arrow.addPoint(x+2, y); 173 } 174 else 175 arrow.addPoint(x, y); 176 } 177 else if (pos == SwingConstants.RIGHT) 178 { 179 x += rect.width; 180 y += rect.height/2; 181 if (from) 182 { 183 arrow.addPoint(x, y-2); 184 arrow.addPoint(x, y+2); 185 } 186 else 187 arrow.addPoint(x, y); 188 } 189 else if (pos == SwingConstants.LEFT) 190 { 191 y += rect.height/2; 192 if (from) 193 { 194 arrow.addPoint(x, y-2); 195 arrow.addPoint(x, y+2); 196 } 197 else 198 arrow.addPoint(x, y); 199 } 200 else { 202 x += rect.width/2; 203 y += rect.height; 204 if (from) 205 { 206 arrow.addPoint(x-2, y); 207 arrow.addPoint(x+2, y); 208 } 209 else 210 arrow.addPoint(x, y); 211 } 212 } 214 218 public Dimension getPreferredSize() 219 { 220 if (m_from == null || m_to == null) 221 return super.getPreferredSize(); 222 int width = Math.max(m_from.x + m_from.width, m_to.x + m_to.width); 224 int height = Math.max(m_from.y + m_from.height, m_to.y + m_to.height); 225 return new Dimension(width, height); 227 } 229 233 public String toString() 234 { 235 StringBuffer sb = new StringBuffer ("WFLine["); 236 sb.append(getAD_WF_Node_ID()).append("->").append(getAD_WF_Next_ID()); 237 sb.append("]"); 238 return sb.toString(); 239 } 241 } | Popular Tags |