KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > apps > wf > WFNode


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2002 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

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 /**
25  * Work Flow Node.
26  * Listen to PropertyChange for selection
27  *
28  * @author Jorg Janke
29  * @version $Id: WFNode.java,v 1.5 2003/11/06 07:08:28 jjanke Exp $
30  */

31 public class WFNode extends JLabel
32     implements MouseListener, MouseMotionListener
33 {
34     /**
35      * Create WF Node
36      * @param node model
37      */

38     public WFNode (MWFNode node)
39     {
40         super (node.getName(true), new WFIcon(node.getAction()), JLabel.CENTER);
41         m_node = node;
42         //
43
setVerticalAlignment(JLabel.CENTER);
44         setVerticalTextPosition(JLabel.BOTTOM);
45         setHorizontalTextPosition(JLabel.CENTER);
46         //
47
String JavaDoc description = node.getDescription(true);
48         if (description != null && description.length() > 0)
49             setToolTipText(description);
50         //
51
setLocation(node.getXposition(), node.getYposition());
52         Log.trace(Log.l4_Data, "WFNode " + node.getAD_WF_Node_ID(), getLocation());
53         //
54
this.addMouseListener(this);
55         this.addMouseMotionListener(this);
56     } // WFNode
57

58     /** ID */
59     private MWFNode m_node = null;
60
61     /** Selected Property value */
62     public static String JavaDoc PROPERTY_SELECTED = "selected";
63     /** Selected Value */
64     private boolean m_selected = false;
65     /** Was node moved */
66     private boolean m_moved = false;
67
68     /** ReadWrite Mode (see WFPanel) */
69     private boolean m_readWrite = Ini.getPropertyBool(Ini.P_COMPIERESYS);
70
71     /*************************************************************************/
72
73     /** Mouse Point for dragging */
74     private Point m_mousePoint = null;
75
76     /**
77      * Mouse Clicked.
78      * Start Action.
79      * Sequence: pressed - clicked - released
80      * @param e event
81      */

82     public void mouseClicked(MouseEvent e)
83     {
84         if (e.getClickCount() > 1)
85         {
86             firePropertyChange(PROPERTY_SELECTED, false, true);
87             setSelected (true);
88         }
89     } // mouseClicked
90

91     /**
92      * Mouse Pressed.
93      * Save position
94      * Sequence: pressed - dragged/clicked - released
95      * @param e event
96      */

97     public void mousePressed(MouseEvent e)
98     {
99         m_mousePoint = e.getPoint();
100     } // mousePressed
101

102     /**
103      * Mouse Released.
104      * After drag - repaint
105      * @param e event
106      */

107     public void mouseReleased(MouseEvent e)
108     {
109     // System.out.println("mouseReleased - x=" + getX() + ", y=" + getY());
110
getParent().doLayout();
111         getParent().repaint();
112         //
113
if (m_moved)
114             m_node.setPosition(getLocation());
115         m_moved = false;
116     } // mouseReleased
117

118     /**
119      * Mouse entered. NOP
120      * @param e event
121      */

122     public void mouseEntered(MouseEvent e) {}
123
124     /**
125      * Mouse exited. NOP
126      * @param e event
127      */

128     public void mouseExited(MouseEvent e) {}
129
130     /**
131      * Mouse moved. NOP
132      * @param e event
133      */

134     public void mouseMoved(MouseEvent e) {}
135
136     /**
137      * Mouse dragged.
138      * @param e event
139      */

140     public void mouseDragged (MouseEvent e)
141     {
142         if (!m_readWrite)
143             return;
144         // Convert from Node to Panel coordinates
145
Point p = SwingUtilities.convertPoint(this, e.getPoint(), this.getParent());
146         // Subtract Pressed (start point)
147
p.x -= m_mousePoint.x;
148         p.y -= m_mousePoint.y;
149         // Position in panel
150
setLocation(p);
151         m_moved = true;
152     } // mouseDragged
153

154     /*************************************************************************/
155
156     /**
157      * Set Selected
158      * @param selected selected
159      */

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     } // setSelected
166

167     /**
168      * Get Selected
169      * @return selected
170      */

171     public boolean isSelected()
172     {
173         return m_selected;
174     } // isSelected
175

176     /**
177      * Get Node ID
178      * @return Node ID
179      */

180     public int getAD_WF_Node_ID()
181     {
182         return m_node.getAD_WF_Node_ID();
183     } // getAD_WF_Node_ID
184

185     /**
186      * Get Node Model
187      * @return Node Model
188      */

189     public MWFNode getModel()
190     {
191         return m_node;
192     } // getModel
193

194     /**
195      * Get Bounds of Icon
196      * @return Bounds
197      */

198     public Rectangle getIconBounds()
199     {
200         Icon icon = getIcon();
201         Rectangle bounds = getBounds();
202         bounds.x += (bounds.width-icon.getIconWidth()) / 2;
203         //
204
bounds.width = icon.getIconWidth();
205         bounds.height = icon.getIconHeight();
206         //
207
return bounds;
208     } // getIconBounds
209

210     /**
211      * String Representation
212      * @return info
213      */

214     public String JavaDoc toString()
215     {
216         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("WFNode[");
217         sb.append(getAD_WF_Node_ID())
218             .append(",").append(getBounds())
219             .append("]");
220         return sb.toString();
221     } // toString
222

223 } // WFNode
224
Popular Tags