1 14 package org.compiere.apps.wf; 15 16 import java.awt.*; 17 import java.awt.event.*; 18 import javax.swing.*; 19 20 import org.compiere.apps.*; 21 import org.compiere.model.*; 22 import org.compiere.util.*; 23 24 31 public class WFNode extends JLabel 32 implements MouseListener, MouseMotionListener 33 { 34 38 public WFNode (MWFNode node) 39 { 40 super (node.getName(true), new WFIcon(node.getAction()), JLabel.CENTER); 41 m_node = node; 42 setVerticalAlignment(JLabel.CENTER); 44 setVerticalTextPosition(JLabel.BOTTOM); 45 setHorizontalTextPosition(JLabel.CENTER); 46 String description = node.getDescription(true); 48 if (description != null && description.length() > 0) 49 setToolTipText(description); 50 setLocation(node.getXposition(), node.getYposition()); 52 Log.trace(Log.l4_Data, "WFNode " + node.getAD_WF_Node_ID(), getLocation()); 53 this.addMouseListener(this); 55 this.addMouseMotionListener(this); 56 } 58 59 private MWFNode m_node = null; 60 61 62 public static String PROPERTY_SELECTED = "selected"; 63 64 private boolean m_selected = false; 65 66 private boolean m_moved = false; 67 68 69 private boolean m_readWrite = Ini.getPropertyBool(Ini.P_COMPIERESYS); 70 71 72 73 74 private Point m_mousePoint = null; 75 76 82 public void mouseClicked(MouseEvent e) 83 { 84 if (e.getClickCount() > 1) 85 { 86 firePropertyChange(PROPERTY_SELECTED, false, true); 87 setSelected (true); 88 } 89 } 91 97 public void mousePressed(MouseEvent e) 98 { 99 m_mousePoint = e.getPoint(); 100 } 102 107 public void mouseReleased(MouseEvent e) 108 { 109 getParent().doLayout(); 111 getParent().repaint(); 112 if (m_moved) 114 m_node.setPosition(getLocation()); 115 m_moved = false; 116 } 118 122 public void mouseEntered(MouseEvent e) {} 123 124 128 public void mouseExited(MouseEvent e) {} 129 130 134 public void mouseMoved(MouseEvent e) {} 135 136 140 public void mouseDragged (MouseEvent e) 141 { 142 if (!m_readWrite) 143 return; 144 Point p = SwingUtilities.convertPoint(this, e.getPoint(), this.getParent()); 146 p.x -= m_mousePoint.x; 148 p.y -= m_mousePoint.y; 149 setLocation(p); 151 m_moved = true; 152 } 154 155 156 160 public void setSelected (boolean selected) 161 { 162 m_selected = selected; 163 ((WFIcon)getIcon()).setSelected (m_selected); 164 setForeground(m_selected ? Color.blue : Color.black); 165 } 167 171 public boolean isSelected() 172 { 173 return m_selected; 174 } 176 180 public int getAD_WF_Node_ID() 181 { 182 return m_node.getAD_WF_Node_ID(); 183 } 185 189 public MWFNode getModel() 190 { 191 return m_node; 192 } 194 198 public Rectangle getIconBounds() 199 { 200 Icon icon = getIcon(); 201 Rectangle bounds = getBounds(); 202 bounds.x += (bounds.width-icon.getIconWidth()) / 2; 203 bounds.width = icon.getIconWidth(); 205 bounds.height = icon.getIconHeight(); 206 return bounds; 208 } 210 214 public String toString() 215 { 216 StringBuffer sb = new StringBuffer ("WFNode["); 217 sb.append(getAD_WF_Node_ID()) 218 .append(",").append(getBounds()) 219 .append("]"); 220 return sb.toString(); 221 } 223 } | Popular Tags |