I m p l e m e n t i n g   a   S t a t e   E d i t o r   u s i n g   H o t D r a w / V 
 
 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 D o r i n   S a n d u 
 
 s a n d u @ u r s a m i n o r . s c s . c a r l e t o n . c a 
 
 C e n t e r   f o r   O b j e c t   O r i e n t e d   P r o g r a m m i n g   
 
 C a r l e t o n   U n i v e r s i t y ,   C a n a d a 
 
 
 
 T h i s   p a p e r   o f f e r s   a   c o o k b o o k   f o r   d e v e l o p i n g   g r a p h i c a l   e d i t o r s   u s i n g   t h e   
 
 H o t D r a w / V   f r a m e w o r k .   A   f i n i t e   s t a t e   m a c h i n e   e d i t o r   i s   b u i l d   t o   i l l u s t r a t e   
 
 t h e   m a j o r   s t e p s   o f   t h e   p r o c e s s .   T h e   s t e p s   d o n  t   n e c e s s a r i l y   h a v e   t o   b e   
 
 p e r f o r m e d   i n   t h e   o r d e r   d e s c r i b e d   h e r e . 
 
 
 
 *   L i s t   t h e   r e q u i r e d   f i g u r e s 
 
 T h e   f i g u r e s   n e e d e d   f o r   t h e   s t a t e   e d i t o r   a r e   s t a r t ,   s t o p ,   a n d   n o r m a l   s t a t e s .     
 
 A l s o   w e   n e e d   a r r o w   f i g u r e s   t o   c o n n e c t   t h e   s t a t e s .   A l l   s t a t e   f i g u r e s   s h o u l d   
 
 d i s p l a y   a   l a b e l   t h a t   i s   m o d i f i a b l e   b y   t h e   u s e r . 
 
 
 
 *   L i s t   t h e   c o n s t r a i n t s   b e t w e e n   t h e   f i g u r e s 
 
 S t a t e   c o n n e c t o r s   s h o u l d   s t i c k   t o   t h e   f i g u r e s   i . e .   w h e n   m o v i n g   o n e   o f   a   g r o u p   
 
 o f   c o n n e c t e d   s t a t e s ,   t h e   m o v e d   s t a t e   c o n n e c t o r s   s h o u l d   c h a n g e   p o s i t i o n   t o o .     
 
 A l s o   w h e n   c h a n g i n g   a   s t a t e   l a b e l ,   t h e   s t a t e   s h o u l d   r e s i z e   a c c o r d i n g   t o   t h e   
 
 s i z e   o f   t h e   l a b e l . 
 
 
 
 *   E s t a b l i s h   u s e r - e d i t o r   i n t e r a c t i o n 
 
 T h e   u s e r   s h o u l d   b e   a b l e   t o   c r e a t e   a n d   d e l e t e   s t a t e   f i g u r e s   a n d   s t a t e   c o n n e c t o r s .     
 
 A l s o   t h e   u s e r   s h o u l d   b e   a b l e   t o   l a b e l   a n y   o f   t h e   s t a t e   f i g u r e s   a n d   c h a n g e   t h e   
 
 l a b e l s   f o n t .   C o m m o n   t a s k s   i n c l u d e   s c r o l l i n g ,   s a v i n g   a   d r a w i n g   t o   a   f i l e ,   
 
 l o a d i n g   a   d r a w i n g   f r o m   a   f i l e ,   c u t ,   c o p y ,   p a s t e ,   e t c . 
 
 
 
 *   I m p l e m e n t   t h e   f i g u r e s 
 
 
 
 S t a t e s 
 
 ^ ^ ^ ^ ^ ^ 
 
 S t a t e   f i g u r e s   h a v e   t o   b e   s u b c l a s s e s   o f   C o m p o s i t e F i g u r e   b e c a u s e   t h e y   c o n t a i n   t w o   
 
 f i g u r e s ,   a n   e l l i p s e   f i g u r e   a n d   a   t e x t   f i g u r e ,   a n d   i n   t h e   c a s e   o f   s t o p   s t a t e s ,   t w o   
 
 e l l i p s e   f i g u r e s   a n d   a   t e x t   f i g u r e .   A   n e w   i n s t a n c e   o f   a   s t a t e   c l a s s   s h o u l d   b e   
 
 o b t a i n e d   e v e r y   t i m e   t h e   u s e r   p r e s s e s   a   c r e a t i o n   t o o l   i n s i d e   t h e   d r a w i n g   a r e a ;   
 
 t h i s   i s   a c c o m p l i s h e d   v i a   s e n d i n g   a   c r e a t e N o t i f y i n g :   m e s s a g e   t o   t h e   s t a t e   f i g u r e   
 
 c l a s s   w i t h   a   d r a w i n g   p a n e   a s   a n   a r g u m e n t .   T h e   c r e a t e N o t i f y i n g :   m e s s a g e   s i m p l y   
 
 c r e a t e s   a   n e w   s t a t e   a n d   i n i t i a l i z e s   i t .   I t   i s   t h e   m e s s a g e   i n i t i a l i z e I n A r e a :   t h a t 
 
 t a k e s   c a r e   o f   i n i t i a l i z i n g   t h e   s t a t e ,   i . e .   a d d i n g   a l l   t h e   c o m p o n e n t   f i g u r e s ,   t h e   
 
 e l l i p s e   f i g u r e s   a n d   t h e   t e x t   f i g u r e ,   a n d   c r e a t i n g   t h e   c o n s t r a i n t   o b j e c t s . 
 
 
 
 I n   t h e   i n i t i a l i z e I n A r e a :   m e t h o d ,   a   t e x t   a n d   a n   e l l i p s e   f i g u r e   a r e   c r e a t e d   w h i c h   
 
 a r e   s e t   t o   b e   t h e   c o m p o n e n t s   o f   t h e   c o m p o s i t e   f i g u r e .   S i n c e   t h e   e l l i p s e   s i z e   i s   
 
 d e p e n d e n t   t o   t h e   l a b e l   s i z e ,   a   c o n t r a i n t   i s   c r e a t e d   w i t h   t h e   s i n k   s e t   t o   t h e   s t a t e   
 
 i t s e l f   a n d   t h e   s o u r c e   t o   t h e   t e x t   f i g u r e ,   i . e .   t h e   l a b e l ;   e v e r y t i m e   t h e   t e x t   l a b e l   
 
 i s   c h a n g e d ,   t h e   a c t i o n   b l o c k   i s   e v a l u a t e d   w i t h   t h e   s t a t e   a n d   t h e   t e x t   f i g u r e   a s   
 
 a r g u m e n t s .   T h e   u p d a t e P o s i t i o n s   m e t h o d   i n s i d e   t h e   a c t i o n   b l o c k   r e c a l c u l a t e s   t h e   
 
 s i z e   o f   t h e   e l l i p s e   a s   a   f u n c t i o n   o f   t h e   l a b e l   s i z e   a n d   r e s e t V i s i b l e A r e a   r e c o m p u t e s   
 
 t h e   b o u n d i n g   b o x   o f   t h e   e n t i r e   s t a t e   f i g u r e .     T h e   i n i t i a l i z e I n A r e a :   m e t h o d   i s   
 
 o v e r w r i t t e n   i n   S t a r t S t a t e   a n d   S t o p S t a t e   c l a s s e s   s o   t h a t ,   i n   t h e   f o r m e r ,   t h e   w i d t h   
 
 o f   t h e   e l l i p s e   i s   s e t   t o   4 ,   a n d   i n   t h e   l a t e r ,   a n   e x t r a   e l l i p s e   i s   a d d e d   t o   t h e   
 
 s t a t e   ( a l s o   u p d a t e P o s i t i o n s   i s   m o d i f i e d   t o   t a k e   c a r e   o f   t h e   e x t r a   e l l i p s e ) . 
 
 
 
 C r e a t i o n T o o l s   h a v e   t o   b e   p r o v i d e d   f o r   a l l   s t a t e s .   E a c h   s t a t e   c l a s s   i s   a s s o c i a t e d   
 
 w i t h   a   c r e a t i o n   t o o l   b y   i m p l e m e n t i n g   a   c r e a t i o n T o o l   c l a s s   m e t h o d   t h a t   r e t u r n s   a   
 
 C r e a t i o n T o o l   f o r   t h e   c l a s s   w i t h   a n   a s s o c i a t e d   b i t m a p   t o   b e   d i s p l a y e d   i n   t h e   t o o l   
 
 p a l e t t e . 
 
 
 
 S t a t e   o v e r w r i t e s   t h e   h a n d l e s   m e t h o d   w h i c h   r e t u r n s   a   c o l l e c t i o n   o f   h a n d l e s   f o r   s t a t e   
 
 f i g u r e s   i . e .   f o u r   r e s i z i n g   h a n d l e s   a n d   a   c o n n e c t i o n   h a n d l e .   T h e   f o u r   r e s i z i n g   h a n d l e s   
 
 a r e   i n h e r i t e d   f r o m   t h e   C o m p o s i t e F i g u r e ,   a n d   s i n c e   t h e   u s e r   s h o u l d n  t   b e   a b l e   t o   
 
 r e s i z e   a n y   o f   t h e   s t a t e   f i g u r e s ,   t h e   m e s s a g e   g r o w B y :   s h o u l d   b e   o v e r w r i t t e n   t o o ,   t o   
 
 d o   n o t h i n g .     T h e   a d d i t i o n a l   c o n n e c t i o n   h a n d l e   w i l l   u s e   a   S t a t e C o n n e c t o r   c o n n e c t i o n   
 
 o b j e c t   d e s c r i b e d   l a t e r . 
 
 
 
 T h e   m e n u   o p t i o n s   f o r   s t a t e   f i g u r e s   s h o u l d   b e   t o   c h a n g e   t h e   l a b e l   a n d   i t s   f o n t .     
 
 T h e   m e n u   m e s s a g e   f r o m   C o m p o s i t e F i g u r e   h a s   b e e n   o v e r w r i t t e n   t o   r e t u r n   t h e   n e w   m e n u . 
 
 
 
 S t a t e   C o n n e c t o r 
 
 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 T h e   S t a t e C o n n e c t o r   c l a s s   i s   a   s u b c l a s s   o f   A r r o w F i g u r e .   T h e   d i f f e r e n c e   i s   t h a t   a   
 
 S t a t e C o n n e c t o r  s   a r r o w   h e a d   i s   c o n s t r a i n e d   t o   t h e   m i d d l e   o f   t h e   l i n e .     T h i s   i s   
 
 a c c o m p l i s h e d   b y   o v e r w r i t i n g   t h e   u p d a t e A r r o w   f r o m   t h e   A r r o w F i g u r e   t o   s e t   t h e   t i p   o f   
 
 t h e   a r r o w   t o   t h e   m i d - p o i n t   f r o m   t h e   s t a r t   t o   t h e   e n d   p o i n t   o f   t h e   l i n e .   S i n c e   t h e   
 
 S t a t e C o n n e c t o r   i s   a   P o l y l i n e F i g u r e ,   a n d   p o l y l i n e   f i g u r e s   d i s p l a y   b y   d r a w i n g   a   l i n e   
 
 b e t w e e n   t h e i r   p o i n t s ,   t h e   d i s p l a y O n :   m e t h o d   h a d   t o   b e   s l i g h t l y   m o d i f i e d   t o   a v o i d   
 
 e x t r a   l i n e s . 
 
 
 
 S t a t e C o n n e c t o r s   h a v e   n o   m e n u s ,   t h e r e f o r e   t h e   m e n u   m e s s a g e   r e t u r n s   s e t s   t h e   m e n u   
 
 o p t i o n s   t o   ' n o n e ' . 
 
 
 
 *   I m p l e m e n t   t h e   e d i t o r 
 
 T h e   e d i t o r   i s   i m p l e m e n t e d   b y   s u b c l a s s i n g   t h e   D r a w i n g E d i t o r   c l a s s   a n d   w r i t i n g   a   n e w   
 
 t o o l s   m e t h o d   t h a t   r e t u r n s   a   c o l l e c t i o n   o f   t o o l s   t h a t   s h o u l d   b e   a v a i l a b l e   t o   t h e   u s e r   
 
 i n   t h e   t o o l   p a l e t t e .     T h e   n e w   e d i t o r   n a m e   i s   S t a t e E d i t o r   a n d   i t s   t o o l s   m e t h o d   r e t u r n s . 
 
 T h e   t o o l s   a v a i l a b l e   t o   t h e   u s e r   a r e   o b v i o u s . 
 
 
 
 